﻿using System;
using System.Collections.Generic;
using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;

namespace TestDxfDocument
{
    class Taps
    {
        #region
        //public static void ThreadCuttingTapWithOffsetShank(Dictionary<string, Object> data)  //细柄切削丝锥
        //{
        //    DxfDocument dxf = new DxfDocument();
        //    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
        //    Layer dimensioning = new Layer("dimensioning");    //尺寸层
        //    Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
        //    Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
        //    Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
        //    Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
        //    Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
        //    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
        //    Layer nocutting = new Layer("nocutting");    //非切削层
        //    Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
        //    Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
        //    Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
        //    Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
        //    Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
        //    Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
        //    Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
        //    Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

        //    double pi = Math.PI;


        //    double isframe = 1; //是否有图框 0无1有
        //    //double valuemax = Math.Max()

        //    double tcpd = Convert.ToDouble(data["tcpd"]);
        //    double td = Convert.ToDouble(data["td"]);
        //    double tdz = Convert.ToDouble(data["tdz"]);
        //    double thl = Convert.ToDouble(data["thl"]);
        //    double oal = Convert.ToDouble(data["oal"]);
        //    double tcl = Convert.ToDouble(data["tcl"]);
        //    double dmm = Convert.ToDouble(data["dmm"]);
        //    string path = Convert.ToString(data["path"]);

        //    Vector2 p0 = new Vector2(0, 0);
        //    Vector2 p0p = fun.Polar(p0, 1.5 * pi, oal);
        //    Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
        //    Vector2 p6 = fun.Polar(p0p, 0, tcpd / 2);
        //    Vector2 p5 = new Vector2(p0p.X + td / 2, p0p.Y + tcl);
        //    Vector2 p4 = new Vector2(p5.X, p0p.Y + thl);
        //    Vector2 p3 = new Vector2(p6.X, p4.Y + (td - tcpd) / 2);
        //    Vector2 p2 = new Vector2(p3.X - (tcpd - dmm) / 2, p3.Y + (tcpd - dmm) / 2);
        //    Vector2 p7 = new Vector2(p0.X - p6.X, p6.Y);
        //    Vector2 p8 = new Vector2(p0.X - p5.X, p5.Y);
        //    Vector2 p9 = new Vector2(p0.X - p4.X, p4.Y);
        //    Vector2 p10 = new Vector2(p0.X - p3.X, p3.Y);
        //    Vector2 p11 = new Vector2(p0.X - p2.X, p2.Y);
        //    Vector2 p12 = new Vector2(p0.X - p1.X, p1.Y);

        //    //Vector2[] line1 = { p11, p12, p1, p2 };
        //    //fun.drawBLine(dxf, line1,0.5, contour);
        //    //Vector2[] line2 = { p3, p4, p5, p6, p7, p8, p9, p10 };
        //    //fun.drawBLine(dxf, line2, 0.5, contour);

        //    Vector2 coc1 = fun.Polar(p2, 0, (td - dmm) / 4);
        //    Vector2 coc2 = fun.Polar(p11, pi, (td - dmm) / 4);

        //    //Arc arc1 = fun.DrawArc(p2, coc1, p3);
        //    //Arc arc2 = fun.DrawArc(p10, coc2, p11);
        //    //arc1.Layer = contour;
        //    //arc2.Layer = contour;
        //    //dxf.AddEntity(arc1);
        //    //dxf.AddEntity(arc2);
        //    /*
        //    LwPolyline poly1 = new LwPolyline();
        //    poly1.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly1.Vertexes[0].Bulge = Math.Tan(pi / 8);
        //    poly1.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly1.SetConstantWidth(0.5);
        //    poly1.Layer = contour;
        //    dxf.AddEntity(poly1);
        //    LwPolyline poly2 = new LwPolyline();
        //    poly2.Vertexes.Add(new LwPolylineVertex(p10));
        //    poly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p11));
        //    poly2.SetConstantWidth(0.5);
        //    poly2.Layer = contour;
        //    dxf.AddEntity(poly2);
        //    */

        //    LwPolyline poly = new LwPolyline();
        //    poly.Vertexes.Add(new LwPolylineVertex(p1));
        //    poly.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly.Vertexes[1].Bulge = Math.Tan(pi / 8);
        //    poly.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly.Vertexes.Add(new LwPolylineVertex(p4));
        //    poly.Vertexes.Add(new LwPolylineVertex(p5));
        //    poly.Vertexes.Add(new LwPolylineVertex(p6));
        //    poly.Vertexes.Add(new LwPolylineVertex(p7));
        //    poly.Vertexes.Add(new LwPolylineVertex(p8));
        //    poly.Vertexes.Add(new LwPolylineVertex(p9));
        //    poly.Vertexes.Add(new LwPolylineVertex(p10));
        //    poly.Vertexes[9].Bulge = Math.Tan(pi / 8);
        //    poly.Vertexes.Add(new LwPolylineVertex(p11));
        //    poly.Vertexes.Add(new LwPolylineVertex(p12));
        //    poly.Vertexes.Add(new LwPolylineVertex(p1));
        //    fun.PolyFill(dxf, poly, 0.3, contour);

        //    Line dotline1 = new Line(fun.Polar(p0, pi / 2, 2), fun.Polar(p0p, 1.5 * pi, 2));
        //    dotline1.Linetype = Linetype.Center;
        //    dotline1.Layer = centre;
        //    dxf.AddEntity(dotline1);

        //    Vector2[] xiline1 = { p7, p10 };
        //    fun.drawBLine(dxf, xiline1,0.15, additionalline);
        //    Vector2[] xiline2 = { p6, p3 };
        //    fun.drawBLine(dxf, xiline2,0.15, additionalline);

        //    Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
        //    Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
        //    Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
        //    Vector2 p23 = new Vector2(p20.X, p22.Y);
        //    Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
        //    Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
        //    Vector2 p26 = new Vector2(p25.X, p23.Y);
        //    Vector2 p27 = new Vector2(p24.X, p23.Y);

        //    Vector2[] line3 = { p25, p26, p27, p24, p26 };
        //    fun.drawPline(dxf, line3, contour);
        //    Vector2[] line4 = { p25, p27 };
        //    fun.drawPline(dxf, line4, contour);
        //    Vector2[] line5 = { p21, p22, p23, p20, p22 };
        //    fun.drawPline(dxf, line5, contour);
        //    Vector2[] line6 = { p21, p23 };
        //    fun.drawPline(dxf, line6, contour);

        //    Vector2 p30 = new Vector2(p0.X - td / 8, p11.Y + (dmm - td / 2) / 2 + dmm / 8);
        //    Vector2 p31 = new Vector2(p30.X, p10.Y);
        //    Vector2 p32 = new Vector2(p30.X, p8.Y);
        //    Vector2 p33 = fun.Polar(p0p, pi, td / 16);
        //    Vector2 p34 = fun.Polar(p0p, 0, td / 8);
        //    Vector2 p35 = new Vector2(p34.X, p31.Y);
        //    Vector2 p36 = new Vector2(p34.X, p11.Y);
        //    Vector2 p37 = new Vector2(p1.X, p30.Y);

        //    LwPolyline poly1 = new LwPolyline();
        //    poly1.Vertexes.Add(new LwPolylineVertex(p31));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p30));
        //    poly1.Vertexes[1].Bulge = Math.Tan(pi / 10);
        //    poly1.Vertexes.Add(new LwPolylineVertex(p11));
        //    fun.PolyFill(dxf, poly1, 0.3, contour);
        //    LwPolyline poly2 = new LwPolyline();
        //    poly2.Vertexes.Add(new LwPolylineVertex(p37));
        //    poly2.Vertexes[0].Bulge = Math.Tan(pi / 10);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p36));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p35));
        //    fun.PolyFill(dxf, poly2, 0.3, contour);

        //    LwPolyline poly3 = new LwPolyline();
        //    poly3.Vertexes.Add(new LwPolylineVertex(p31));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p32));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p33));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p34));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p35));
        //    poly3.SetConstantWidth(0.3);
        //    poly3.IsClosed = true;

        //    String[] type = new String[100];
        //    Line[] line = new Line[100];
        //    int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
        //    for (int i = 0; i < numst; i++)
        //    {
        //        type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
        //        if (type[i] == "Line")
        //        {
        //            line[i] = (Line)poly3.Explode()[i];
        //        }
        //    }
        //    fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);
        //    fun.PolyFill(dxf, poly3, 0.3, contour);

        //    /*
        //    Vector2 p0 = new Vector2(0, 0);
        //    Vector2 p1 = new Vector2(10, 0);
        //    Vector2 p2 = new Vector2(10, -25);
        //    Vector2 p3 = new Vector2(5, -25);
        //    Vector2 p4 = new Vector2(0, -20);

        //    LwPolyline poly = new LwPolyline();
        //    poly.Vertexes.Add(new LwPolylineVertex(p0));
        //    poly.Vertexes.Add(new LwPolylineVertex(p1));
        //    poly.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly.Vertexes.Add(new LwPolylineVertex(p4));
        //    poly.SetConstantWidth(0.2);
        //    poly.IsClosed = true;

        //    String[] type = new String[100];
        //    Line[] line = new Line[100];



        //    int numst = poly.Explode().Count;  //记录爆炸后，线段有多少
        //    for (int i = 0; i < numst; i++)
        //    {
        //        type[i] = poly.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
        //        if (type[i] == "Line")
        //        {
        //            line[i] = (Line)poly.Explode()[i];
        //        }
        //    }

        //    fun.hatchsubofline(dxf, type, numst, 5, 12, line);
        //    dxf.AddEntity(poly);
        //    */

        //    DimensionStyle dimensionStyle = fun.CreateDimStyle();
        //    dimensionStyle.ArrowSize = 0.2;
        //    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.TextHeight = 0.5;
        //    double offset = 7;

        //    LinearDimension dim1 = new LinearDimension(new Line(p7, p12), offset * 2, 90, dimensionStyle);
        //    dim1.UserText = String.Format("{0}", oal);
        //    dxf.AddEntity(dim1);

        //    LinearDimension dim2 = new LinearDimension(new Line(p7, p9), offset, 90, dimensionStyle);
        //    dim2.UserText = String.Format("{0}", thl);
        //    dxf.AddEntity(dim2);

        //    LinearDimension dim3 = new LinearDimension(new Line(p1, p12), offset, 0, dimensionStyle);
        //    dim3.UserText = String.Format("{0}", dmm);
        //    dxf.AddEntity(dim3);

        //    LinearDimension dim4 = new LinearDimension(new Line(p5, p6), offset, 270, dimensionStyle);
        //    dim4.UserText = String.Format("{0}", tcl);
        //    dxf.AddEntity(dim4);

        //    LinearDimension dim5 = new LinearDimension(new Line(p6, p7), offset, 180, dimensionStyle);
        //    dim5.UserText = String.Format("{0}", tcpd);
        //    dxf.AddEntity(dim5);

        //    LinearDimension dim6 = new LinearDimension(new Line(p5, p8), offset * 2, 180, dimensionStyle);
        //    dim6.UserText = String.Format("{0}", td);
        //    dxf.AddEntity(dim6);

        //    if(isframe==1)
        //    {
        //        Frame.frameA4Y(dxf, new Vector2(p0.X - 100, p0.Y + 100));
        //    }

        //    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
        //    dxf.Save(path);
        //}

        //public static void ThreadCuttingTapWithReinforcedShank(Dictionary<string, Object> data)  //粗柄切削丝锥
        //{
        //    DxfDocument dxf = new DxfDocument();
        //    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
        //    Layer dimensioning = new Layer("dimensioning");    //尺寸层
        //    Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
        //    Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
        //    Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
        //    Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
        //    Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
        //    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
        //    Layer nocutting = new Layer("nocutting");    //非切削层
        //    Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
        //    Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
        //    Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
        //    Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
        //    Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
        //    Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
        //    Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
        //    Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

        //    double pi = Math.PI;


        //    double tcpd = Convert.ToDouble(data["tcpd"]);
        //    double td = Convert.ToDouble(data["td"]);
        //    double thl = Convert.ToDouble(data["thl"]);
        //    double oal = Convert.ToDouble(data["oal"]);
        //    double tcpl = Convert.ToDouble(data["tcl"]);
        //    double dmm = Convert.ToDouble(data["dmm"]);
        //    double lu = Convert.ToDouble(data["lu"]);
        //    double ls = Convert.ToDouble(data["ls"]);
        //    double dn = Convert.ToDouble(data["dn"]);
        //    double fha = Convert.ToDouble(data["fha"])*pi/180;
        //    string path = Convert.ToString(data["path"]);

        //    Vector2 p0 = new Vector2(0, 0);
        //    Vector2 p0p = new Vector2(p0.X, p0.Y - oal);
        //    Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
        //    Vector2 p2 = fun.Polar(p1, 1.5 * pi, ls);
        //    Vector2 p3 = new Vector2(p0.X + dn / 2, p0p.Y + lu);
        //    Vector2 p4 = new Vector2(p3.X, p0p.Y + thl + 0.5);
        //    Vector2 p5 = new Vector2(p0.X + td / 2, p0p.Y + thl);
        //    Vector2 p6 = new Vector2(p0.X + td / 2, p0p.Y + tcpl);
        //    Vector2 p7 = new Vector2(p0.X + tcpd / 2, p0p.Y);
        //    Vector2 p8 = new Vector2(p0.X - p7.X, p7.Y);
        //    Vector2 p9 = new Vector2(p0.X - p6.X, p6.Y);
        //    Vector2 p10 = new Vector2(p0.X - p5.X, p5.Y);
        //    Vector2 p11 = new Vector2(p0.X - p4.X, p4.Y);
        //    Vector2 p12 = new Vector2(p0.X - p3.X, p3.Y);
        //    Vector2 p13 = new Vector2(p0.X - p2.X, p2.Y);
        //    Vector2 p14 = new Vector2(p0.X - p1.X, p1.Y);

        //    LwPolyline poly1 = new LwPolyline();
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p4));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p5));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p6));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p7));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p8));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p9));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p10));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p11));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p12));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p13));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p14));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    fun.PolyFill(dxf, poly1, 0.3, contour);

        //    Line dotline1 = new Line(fun.Polar(p0, pi / 2, 2), fun.Polar(p0p, 1.5 * pi, 2));
        //    dotline1.Linetype = Linetype.Center;
        //    dotline1.Layer = centre;
        //    dxf.AddEntity(dotline1);

        //    Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
        //    Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
        //    Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
        //    Vector2 p23 = new Vector2(p20.X, p22.Y);
        //    Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
        //    Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
        //    Vector2 p26 = new Vector2(p25.X, p23.Y);
        //    Vector2 p27 = new Vector2(p24.X, p23.Y);

        //    Vector2[] line3 = { p25, p26, p27, p24, p26 };
        //    fun.drawPline(dxf, line3, contour);
        //    Vector2[] line4 = { p25, p27 };
        //    fun.drawPline(dxf, line4, contour);
        //    Vector2[] line5 = { p21, p22, p23, p20, p22 };
        //    fun.drawPline(dxf, line5, contour);
        //    Vector2[] line6 = { p21, p23 };
        //    fun.drawPline(dxf, line6, contour);

        //    Vector2[] line7 = { p2, p13 };
        //    fun.drawBLine(dxf, line7, 0.3, contour);
        //    Vector2[] line8 = { p3, p12 };
        //    fun.drawBLine(dxf, line8, 0.3, contour);
        //    Vector2[] line9 = { p4, p11 };
        //    fun.drawBLine(dxf, line9, 0.3, contour);
        //    Vector2[] line10 = { p5, p10 };
        //    fun.drawBLine(dxf, line10, 0.3, contour);

        //    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
        //    dxf.Save(path);
        //}

        //public static void ThreadFormingTapWithOffsetShank(Dictionary<string, Object> data)  //细柄挤压丝锥
        //{
        //    DxfDocument dxf = new DxfDocument();
        //    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
        //    Layer dimensioning = new Layer("dimensioning");    //尺寸层
        //    Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
        //    Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
        //    Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
        //    Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
        //    Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
        //    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
        //    Layer nocutting = new Layer("nocutting");    //非切削层
        //    Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
        //    Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
        //    Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
        //    Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
        //    Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
        //    Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
        //    Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
        //    Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

        //    double pi = Math.PI;


        //    double tcpd = Convert.ToDouble(data["tcpd"]);
        //    double dmm = Convert.ToDouble(data["dmm"]);
        //    double oal = Convert.ToDouble(data["oal"]);
        //    double thl = Convert.ToDouble(data["thl"]);
        //    double tcl = Convert.ToDouble(data["tcl"]);
        //    double td = Convert.ToDouble(data["td"]);
        //    string path = Convert.ToString(data["path"]);

        //    Vector2 p0 = new Vector2(0, 0);
        //    Vector2 p0p = new Vector2(p0.X, p0.Y - oal);
        //    Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
        //    Vector2 p2 = fun.Polar(p1, 1.5 * pi, oal - thl - (td - tcpd) / 2);
        //    Vector2 p3 = new Vector2(p0.X + td / 2, p0.Y - (oal - thl));
        //    Vector2 p4 = new Vector2(p0.X + td / 2, p0p.Y + tcl);
        //    Vector2 p5 = fun.Polar(p0p, 0, tcpd / 2);
        //    Vector2 p6 = new Vector2(p0.X - p5.X, p5.Y);
        //    Vector2 p7 = new Vector2(p0.X - p4.X, p4.Y);
        //    Vector2 p8 = new Vector2(p0.X - p3.X, p3.Y);
        //    Vector2 p9 = new Vector2(p0.X - p2.X, p2.Y);
        //    Vector2 p10 = new Vector2(p0.X - p1.X, p1.Y);

        //    LwPolyline poly1 = new LwPolyline();
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p4));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p5));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p6));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p7));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p8));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p9));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p10));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    fun.PolyFill(dxf, poly1, 0.3, contour);

        //    Line dotline1 = new Line(fun.Polar(p0, pi / 2, 2), fun.Polar(p0p, 1.5 * pi, 2));
        //    dotline1.Linetype = Linetype.Center;
        //    dotline1.Layer = centre;
        //    dxf.AddEntity(dotline1);

        //    Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
        //    Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
        //    Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
        //    Vector2 p23 = new Vector2(p20.X, p22.Y);
        //    Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
        //    Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
        //    Vector2 p26 = new Vector2(p25.X, p23.Y);
        //    Vector2 p27 = new Vector2(p24.X, p23.Y);

        //    Vector2[] line3 = { p25, p26, p27, p24, p26 };
        //    fun.drawPline(dxf, line3, contour);
        //    Vector2[] line4 = { p25, p27 };
        //    fun.drawPline(dxf, line4, contour);
        //    Vector2[] line5 = { p21, p22, p23, p20, p22 };
        //    fun.drawPline(dxf, line5, contour);
        //    Vector2[] line6 = { p21, p23 };
        //    fun.drawPline(dxf, line6, contour);

        //    Vector2 p30 = new Vector2(p0.X - tcpd / 6, p2.Y + tcpd / 3);
        //    Vector2 p31 = new Vector2(p30.X, p2.Y);
        //    Vector2 p32 = new Vector2(p30.X, p5.Y);
        //    Vector2 p33 = new Vector2(p0.X - p32.X, p32.Y);
        //    Vector2 p34 = new Vector2(p0.X - p31.X, p31.Y);
        //    Vector2 p35 = new Vector2(p0.X - p30.X, p30.Y);

        //    LwPolyline poly2 = new LwPolyline();
        //    poly2.Vertexes.Add(new LwPolylineVertex(p33));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p35));
        //    poly2.Vertexes[1].Bulge = 1;
        //    poly2.Vertexes.Add(new LwPolylineVertex(p30));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p32));
        //    fun.PolyFill(dxf, poly2, 0.3, contour);

        //    Vector2[] line7 = { p9, p31 };
        //    fun.drawBLine(dxf, line7, 0.3, contour);
        //    Vector2[] line8 = { p2, p34 };
        //    fun.drawBLine(dxf, line8, 0.3, contour);

        //    Vector2[] xiline1 = { p2, p5 };
        //    fun.drawPline(dxf, xiline1, contour);
        //    Vector2[] xiline2 = { p6, p9 };
        //    fun.drawPline(dxf, xiline2, contour);

        //    LwPolyline poly3 = new LwPolyline();
        //    poly3.Vertexes.Add(new LwPolylineVertex(p6));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p7));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p8));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p9));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p31));
        //    poly3.Vertexes.Add(new LwPolylineVertex(p32));
        //    poly3.IsClosed = true;
        //    String[] type = new String[100];
        //    Line[] line = new Line[100];
        //    int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
        //    for (int i = 0; i < numst; i++)
        //    {
        //        type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
        //        if (type[i] == "Line")
        //        {
        //            line[i] = (Line)poly3.Explode()[i];
        //        }
        //    }
        //    fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);

        //    LwPolyline poly4 = new LwPolyline();
        //    poly4.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly4.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly4.Vertexes.Add(new LwPolylineVertex(p4));
        //    poly4.Vertexes.Add(new LwPolylineVertex(p5));
        //    poly4.Vertexes.Add(new LwPolylineVertex(p33));
        //    poly4.Vertexes.Add(new LwPolylineVertex(p34));
        //    poly4.IsClosed = true;
        //    String[] type4 = new String[100];
        //    Line[] pline4 = new Line[100];
        //    int numst4 = poly4.Explode().Count;  //记录爆炸后，线段有多少
        //    for (int i = 0; i < numst4; i++)
        //    {
        //        type4[i] = poly4.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
        //        if (type4[i] == "Line")
        //        {
        //            pline4[i] = (Line)poly4.Explode()[i];
        //        }
        //    }
        //    fun.hatchsubofline(dxf, type4, numst4, 5, 12, pline4, hatching);

        //    DimensionStyle dimensionStyle = fun.CreateDimStyle();
        //    dimensionStyle.ArrowSize = 0.2;
        //    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.TextHeight = 0.5;
        //    double offset = 7;

        //    LinearDimension linedim1 = new LinearDimension(new Line(p6, p10), offset * 3, 90, dimensionStyle);
        //    linedim1.UserText = String.Format("{0}", oal);
        //    dxf.AddEntity(linedim1);

        //    LinearDimension linedim2 = new LinearDimension(new Line(p6, p8), offset, 90, dimensionStyle);
        //    linedim2.UserText = String.Format("{0}", thl);
        //    dxf.AddEntity(linedim2);

        //    LinearDimension linedim3 = new LinearDimension(new Line(p1, p10), offset, 0, dimensionStyle);
        //    linedim3.UserText = String.Format("{0}", dmm);
        //    dxf.AddEntity(linedim3);

        //    LinearDimension linedim4 = new LinearDimension(new Line(p4, p5), offset, 270, dimensionStyle);
        //    linedim4.UserText = String.Format("{0}", tcl);
        //    dxf.AddEntity(linedim4);

        //    LinearDimension linedim5 = new LinearDimension(new Line(p5, p6), offset, 180, dimensionStyle);
        //    linedim5.UserText = String.Format("{0}", tcpd);
        //    dxf.AddEntity(linedim5);

        //    LinearDimension linedim6 = new LinearDimension(new Line(p4, p7), offset * 2, 180, dimensionStyle);
        //    linedim6.UserText = String.Format("{0}", td);
        //    dxf.AddEntity(linedim6);

        //    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
        //    dxf.Save(path);
        //}

        //public static void ThreadFormingTapWithReinforcedShank(Dictionary<string, Object> data)  //粗柄挤压丝锥
        //{
        //    DxfDocument dxf = new DxfDocument();
        //    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
        //    Layer dimensioning = new Layer("dimensioning");    //尺寸层
        //    Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
        //    Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
        //    Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
        //    Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
        //    Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
        //    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
        //    Layer nocutting = new Layer("nocutting");    //非切削层
        //    Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
        //    Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
        //    Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
        //    Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
        //    Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
        //    Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
        //    Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
        //    Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

        //    double pi = Math.PI;


        //    double tcpd = Convert.ToDouble(data["tcpd"]);
        //    double dmm = Convert.ToDouble(data["dmm"]);
        //    double oal = Convert.ToDouble(data["oal"]);
        //    double lu = Convert.ToDouble(data["lu"]);
        //    double ls = Convert.ToDouble(data["ls"]);
        //    double thl = Convert.ToDouble(data["thl"]);
        //    double tcl = Convert.ToDouble(data["tcl"]);
        //    double td = Convert.ToDouble(data["td"]);
        //    double dn = Convert.ToDouble(data["dn"]);
        //    string path = Convert.ToString(data["path"]);

        //    Vector2 p0 = new Vector2(0, 0);
        //    Vector2 p0p = new Vector2(p0.X, p0.Y - oal);
        //    Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
        //    Vector2 p2 = fun.Polar(p1, 1.5 * pi, ls);
        //    Vector2 p3 = new Vector2(p0.X + dn / 2, p0p.Y + lu);
        //    Vector2 p4 = new Vector2(p3.X, p0p.Y + thl + 0.5);
        //    Vector2 p5 = new Vector2(p0.X + tcpd / 2, p0p.Y + thl);
        //    Vector2 p6 = new Vector2(p0.X + td / 2, p5.Y);
        //    Vector2 p7 = new Vector2(p6.X, p0p.Y + tcl);
        //    Vector2 p8 = fun.Polar(p0p, 0, tcpd / 2);
        //    Vector2 p9 = new Vector2(p0.X - p8.X, p8.Y);
        //    Vector2 p10 = new Vector2(p0.X - p7.X, p7.Y);
        //    Vector2 p11 = new Vector2(p0.X - p6.X, p6.Y);
        //    Vector2 p12 = new Vector2(p0.X - p5.X, p5.Y);
        //    Vector2 p13 = new Vector2(p0.X - p4.X, p4.Y);
        //    Vector2 p14 = new Vector2(p0.X - p3.X, p3.Y);
        //    Vector2 p15 = new Vector2(p0.X - p2.X, p2.Y);
        //    Vector2 p16 = new Vector2(p0.X - p1.X, p1.Y);

        //    LwPolyline poly1 = new LwPolyline();
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p4));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p5));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p6));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p7));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p8));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p9));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p10));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p11));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p12));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p13));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p14));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p15));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p16));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    fun.PolyFill(dxf, poly1, 0.3, contour);

        //    Line dotline1 = new Line(fun.Polar(p0, pi / 2, 2), fun.Polar(p0p, 1.5 * pi, 2));
        //    dotline1.Linetype = Linetype.Center;
        //    dotline1.Layer = centre;
        //    dxf.AddEntity(dotline1);

        //    Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
        //    Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
        //    Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
        //    Vector2 p23 = new Vector2(p20.X, p22.Y);
        //    Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
        //    Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
        //    Vector2 p26 = new Vector2(p25.X, p23.Y);
        //    Vector2 p27 = new Vector2(p24.X, p23.Y);

        //    Vector2[] line3 = { p25, p26, p27, p24, p26 };
        //    fun.drawPline(dxf, line3, contour);
        //    Vector2[] line4 = { p25, p27 };
        //    fun.drawPline(dxf, line4, contour);
        //    Vector2[] line5 = { p21, p22, p23, p20, p22 };
        //    fun.drawPline(dxf, line5, contour);
        //    Vector2[] line6 = { p21, p23 };
        //    fun.drawPline(dxf, line6, contour);

        //    Vector2[] line7 = { p2, p15 };
        //    fun.drawBLine(dxf, line7, 0.3, contour);
        //    Vector2[] line8 = { p3, p14 };
        //    fun.drawBLine(dxf, line8, 0.3, contour);
        //    Vector2[] line9 = { p4, p13 };
        //    fun.drawBLine(dxf, line9, 0.3, contour);
        //    Vector2[] line10 = { p5, p12 };
        //    fun.drawBLine(dxf, line10, 0.3, contour);

        //    Vector2[] xiline1 = { p5, p8 };
        //    fun.drawPline(dxf, xiline1, contour);
        //    Vector2[] xiline2 = { p9, p12 };
        //    fun.drawPline(dxf, xiline2, contour);

        //    LwPolyline hatchpoly1 = new LwPolyline();
        //    hatchpoly1.Vertexes.Add(new LwPolylineVertex(p6));
        //    hatchpoly1.Vertexes.Add(new LwPolylineVertex(p7));
        //    hatchpoly1.Vertexes.Add(new LwPolylineVertex(p8));
        //    hatchpoly1.Vertexes.Add(new LwPolylineVertex(p9));
        //    hatchpoly1.Vertexes.Add(new LwPolylineVertex(p10));
        //    hatchpoly1.Vertexes.Add(new LwPolylineVertex(p11));
        //    hatchpoly1.IsClosed = true;
        //    String[] htype1 = new String[100];
        //    Line[] hline1 = new Line[100];
        //    int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
        //    for (int i = 0; i < hnumst1; i++)
        //    {
        //        htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
        //        if (htype1[i] == "Line")
        //        {
        //            hline1[i] = (Line)hatchpoly1.Explode()[i];
        //        }
        //    }
        //    fun.hatchsubofline(dxf, htype1, hnumst1, 5, 12, hline1, hatching);

        //    DimensionStyle dimensionStyle = fun.CreateDimStyle();
        //    dimensionStyle.ArrowSize = 0.2;
        //    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.TextHeight = 0.5;
        //    double offset = 7;

        //    LinearDimension linedim1 = new LinearDimension(new Line(p16, p9), offset * 3, 90, dimensionStyle);
        //    linedim1.UserText = String.Format("{0}", oal);
        //    dxf.AddEntity(linedim1);

        //    LinearDimension linedim2 = new LinearDimension(new Line(p15, p16), offset, 90, dimensionStyle);
        //    linedim2.UserText = String.Format("{0}", ls);
        //    dxf.AddEntity(linedim2);

        //    LinearDimension linedim3 = new LinearDimension(new Line(p9, p14), offset * 2, 90, dimensionStyle);
        //    linedim3.UserText = String.Format("{0}", lu);
        //    dxf.AddEntity(linedim3);

        //    LinearDimension linedim4 = new LinearDimension(new Line(p9, p11), offset, 90, dimensionStyle);
        //    linedim4.UserText = String.Format("{0}", thl);
        //    dxf.AddEntity(linedim4);

        //    LinearDimension linedim5 = new LinearDimension(new Line(p1, p16), offset, 0, dimensionStyle);
        //    linedim5.UserText = String.Format("{0}", dmm);
        //    dxf.AddEntity(linedim5);

        //    LinearDimension linedim6 = new LinearDimension(new Line(p7, p8), offset, 270, dimensionStyle);
        //    linedim6.UserText = String.Format("{0}", tcl);
        //    dxf.AddEntity(linedim6);

        //    LinearDimension linedim7 = new LinearDimension(new Line(p8, p9), offset, 180, dimensionStyle);
        //    linedim7.UserText = String.Format("{0}", tcpd);
        //    dxf.AddEntity(linedim7);

        //    LinearDimension linedim8 = new LinearDimension(new Line(p7, p10), offset * 2, 180, dimensionStyle);
        //    linedim8.UserText = String.Format("{0}", td);
        //    dxf.AddEntity(linedim8);

        //    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
        //    dxf.Save(path);
        //}

        //public static void ThreadCuttingDieRoundShape(Dictionary<string, Object> data)  //圆板牙
        //{
        //    DxfDocument dxf = new DxfDocument();
        //    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
        //    Layer dimensioning = new Layer("dimensioning");    //尺寸层
        //    Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
        //    Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
        //    Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
        //    Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
        //    Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
        //    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
        //    Layer nocutting = new Layer("nocutting");    //非切削层
        //    Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
        //    Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
        //    Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
        //    Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
        //    Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
        //    Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
        //    Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
        //    Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

        //    double pi = Math.PI;


        //    double oal = Convert.ToDouble(data["oal"]);
        //    double bd = Convert.ToDouble(data["bd"]);
        //    double td = Convert.ToDouble(data["td"]);
        //    double tdn = Convert.ToDouble(data["tdn"]);
        //    double tdz = Convert.ToDouble(data["tdz"]);
        //    double ddch = Convert.ToDouble(data["ddch"]);
        //    double ddchc = Convert.ToDouble(data["ddchc"]);
        //    double dchc = Convert.ToDouble(data["dchc"]);
        //    string path =  Convert.ToString(data["path"]);

        //    Vector2 p0 = new Vector2(0, 0);


        //}

        //public static void ThreadCuttingDieHexagonalShape(Dictionary<string, Object> data)  //六角板牙
        //{
        //    DxfDocument dxf = new DxfDocument();
        //    Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
        //    Layer dimensioning = new Layer("dimensioning");    //尺寸层
        //    Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
        //    Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
        //    Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
        //    Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
        //    Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
        //    Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
        //    Layer nocutting = new Layer("nocutting");    //非切削层
        //    Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
        //    Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
        //    Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
        //    Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
        //    Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
        //    Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
        //    Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
        //    Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

        //    double pi = Math.PI;


        //    double oal = Convert.ToDouble(data["oal"]);
        //    double td = Convert.ToDouble(data["td"]);
        //    double drvs = Convert.ToDouble(data["drvs"]);
        //    double tp = Convert.ToDouble(data["tp"]);
        //    string path = Convert.ToString(data["path"]);

        //    double le = drvs * 0.5 / Math.Sin(pi / 3);
        //    double td1 = td - 1.0825 * tp;
        //    double d1 = td / 2.2;

        //    Vector2 p0 = new Vector2(0, 0);
        //    Vector2 p1 = fun.Polar(p0, pi, le);
        //    Vector2 p2 = fun.Polar(p0, 4.0 / 3 * pi, le);
        //    Vector2 p3 = fun.Polar(p0, 5.0 / 3 * pi, le);
        //    Vector2 p4 = fun.Polar(p0, 0, le);
        //    Vector2 p5 = fun.Polar(p0, 1.0 / 3 * pi, le);
        //    Vector2 p6 = fun.Polar(p0, 2.0 / 3 * pi, le);

        //    LwPolyline poly1 = new LwPolyline();
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p2));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p3));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p4));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p5));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p6));
        //    poly1.Vertexes.Add(new LwPolylineVertex(p1));
        //    fun.PolyFill(dxf, poly1, 0.3, contour);

        //    double ang1 = Math.Asin(d1 * 0.5 / td1);

        //    Vector2 p11 = fun.Polar(p0, pi - ang1, td1);
        //    Vector2 p12 = fun.Polar(p11, pi, 1.0825 * tp);
        //    Vector2 p13 = fun.Polar(p12, pi, 1.5 * tp);
        //    Vector2 p34 = new Vector2(p0.X - p11.X, p11.Y);
        //    Vector2 p33 = new Vector2(p0.X - p12.X, p12.Y);
        //    Vector2 p32 = new Vector2(p0.X - p13.X, p13.Y);
        //    Vector2 p14 = new Vector2(p13.X, p0.Y - p13.Y);
        //    Vector2 p15 = new Vector2(p12.X, p0.Y - p12.Y);
        //    Vector2 p16 = new Vector2(p11.X, p0.Y - p11.Y);
        //    Vector2 p29 = new Vector2(p34.X, p0.Y - p34.Y);
        //    Vector2 p30 = new Vector2(p33.X, p0.Y - p33.Y);
        //    Vector2 p31 = new Vector2(p32.X, p0.Y - p32.Y);

        //    Vector2 p41 = fun.Polar(p0, pi - ang1 - pi / 3, td1);
        //    Vector2 p42 = fun.Polar(p41, 2.0 / 3 * pi, 1.0825 * tp);
        //    Vector2 p43 = fun.Polar(p42, 2.0 / 3 * pi, 1.5 * tp);
        //    Vector2 p44 = fun.Polar(p43, 7.0 / 6 * pi, d1);
        //    Vector2 p45 = fun.Polar(p42, 7.0 / 6 * pi, d1);
        //    Vector2 p46 = fun.Polar(p41, 7.0 / 6 * pi, d1);
        //    Vector2 p35 = new Vector2(p0.X - p46.X, p46.Y);
        //    Vector2 p36 = new Vector2(p0.X - p45.X, p45.Y);
        //    Vector2 p37 = new Vector2(p0.X - p44.X, p44.Y);
        //    Vector2 p38 = new Vector2(p0.X - p43.X, p43.Y);
        //    Vector2 p39 = new Vector2(p0.X - p42.X, p42.Y);
        //    Vector2 p40 = new Vector2(p0.X - p41.X, p41.Y);

        //    Vector2 p17 = new Vector2(p46.X, p0.Y - p46.Y);
        //    Vector2 p18 = new Vector2(p45.X, p0.Y - p45.Y);
        //    Vector2 p19 = new Vector2(p44.X, p0.Y - p44.Y);
        //    Vector2 p20 = new Vector2(p43.X, p0.Y - p43.Y);
        //    Vector2 p21 = new Vector2(p42.X, p0.Y - p42.Y);
        //    Vector2 p22 = new Vector2(p41.X, p0.Y - p41.Y);
        //    Vector2 p23 = new Vector2(p40.X, p0.Y - p40.Y);
        //    Vector2 p24 = new Vector2(p39.X, p0.Y - p39.Y);
        //    Vector2 p25 = new Vector2(p38.X, p0.Y - p38.Y);
        //    Vector2 p26 = new Vector2(p37.X, p0.Y - p37.Y);
        //    Vector2 p27 = new Vector2(p36.X, p0.Y - p36.Y);
        //    Vector2 p28 = new Vector2(p35.X, p0.Y - p35.Y);

        //    LwPolyline poly2 = new LwPolyline();
        //    poly2.Vertexes.Add(new LwPolylineVertex(p11));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p13));
        //    poly2.Vertexes[1].Bulge = 1;
        //    poly2.Vertexes.Add(new LwPolylineVertex(p14));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p16));
        //    poly2.Vertexes[3].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p17));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p19));
        //    poly2.Vertexes[5].Bulge = 1;
        //    poly2.Vertexes.Add(new LwPolylineVertex(p20));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p22));
        //    poly2.Vertexes[7].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p23));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p25));
        //    poly2.Vertexes[9].Bulge = 1;
        //    poly2.Vertexes.Add(new LwPolylineVertex(p26));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p28));
        //    poly2.Vertexes[11].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p29));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p31));
        //    poly2.Vertexes[13].Bulge = 1;
        //    poly2.Vertexes.Add(new LwPolylineVertex(p32));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p34));
        //    poly2.Vertexes[15].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p35));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p37));
        //    poly2.Vertexes[17].Bulge = 1;
        //    poly2.Vertexes.Add(new LwPolylineVertex(p38));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p40));
        //    poly2.Vertexes[19].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p41));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p43));
        //    poly2.Vertexes[21].Bulge = 1;
        //    poly2.Vertexes.Add(new LwPolylineVertex(p44));
        //    poly2.Vertexes.Add(new LwPolylineVertex(p46));
        //    poly2.Vertexes[23].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
        //    poly2.Vertexes.Add(new LwPolylineVertex(p11));
        //    fun.PolyFill(dxf, poly2, 0.3, contour);

        //    Arc arc1 = fun.DrawArc(p45, p0, p12);
        //    arc1.Layer = contour;
        //    dxf.AddEntity(arc1);
        //    Arc arc2 = fun.DrawArc(p15, p0, p18);
        //    arc2.Layer = contour;
        //    dxf.AddEntity(arc2);
        //    Arc arc3 = fun.DrawArc(p21, p0, p24);
        //    arc3.Layer = contour;
        //    dxf.AddEntity(arc3);
        //    Arc arc4 = fun.DrawArc(p27, p0, p30);
        //    arc4.Layer = contour;
        //    dxf.AddEntity(arc4);
        //    Arc arc5 = fun.DrawArc(p33, p0, p36);
        //    arc5.Layer = contour;
        //    dxf.AddEntity(arc5);
        //    Arc arc6 = fun.DrawArc(p39, p0, p42);
        //    arc6.Layer = contour;
        //    dxf.AddEntity(arc6);

        //    Vector2 po1 = new Vector2(p4.X + drvs, p5.Y);
        //    Vector2 po2 = new Vector2(po1.X, p3.Y);
        //    Vector2 po3 = fun.Polar(po2, 0, oal);
        //    Vector2 po4 = new Vector2(po3.X, po1.Y);

        //    LwPolyline poly3 = new LwPolyline();
        //    poly3.Vertexes.Add(new LwPolylineVertex(po1));
        //    poly3.Vertexes.Add(new LwPolylineVertex(po2));
        //    poly3.Vertexes.Add(new LwPolylineVertex(po3));
        //    poly3.Vertexes.Add(new LwPolylineVertex(po4));
        //    poly3.Vertexes.Add(new LwPolylineVertex(po1));
        //    fun.PolyFill(dxf, poly3, 0.3, contour);

        //    Vector2[] cenline1 = { fun.Polar(p1, pi, 1), fun.Polar(p4, 0, 1) };
        //    fun.drawPlinetype(dxf, cenline1, centre, Linetype.Center);
        //    Vector2[] cenline2 = { new Vector2(po1.X - 1, p0.Y), new Vector2(po4.X + 1, p0.Y) };
        //    fun.drawPlinetype(dxf, cenline2, centre, Linetype.Center);

        //    DimensionStyle dimensionStyle = fun.CreateDimStyle();
        //    dimensionStyle.ArrowSize = 0.2;
        //    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
        //    dimensionStyle.TextHeight = 0.5;
        //    double offset = 7;

        //    LinearDimension linedim1 = new LinearDimension(new Line(p4, p6), offset * 3, 300, dimensionStyle);
        //    linedim1.UserText = String.Format("{0}", drvs);
        //    dxf.AddEntity(linedim1);

        //    LinearDimension linedim2 = new LinearDimension(new Line(po1, po4), offset, 0, dimensionStyle);
        //    linedim2.UserText = String.Format("{0}", oal);
        //    dxf.AddEntity(linedim2);

        //    dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
        //    dxf.Save(path);
        //}
        #endregion

        //2021 03 04 modify
        //删除未用的图层
        public static void test(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线

            double pi = Math.PI;

            double tcpd = 12.5;
            double td = 14.0;
            //double tdz = 19.0;
            double thl = 22.0;
            double oal = 100.0;
            double tcl = 2.0;
            double dmm = 11.0;
            string path = "E:\\dxfp\\ThreadCuttingTapWithOffsetShank.dxf";
            double scale; //比例系数

            #region data取值

            if (data.ContainsKey("oal"))
            {
                oal = Convert.ToDouble(data["oal"]);
            }

            if (oal <= 50)
            {
                scale = 2.2;
            }
            else if (50 < oal && oal <= 75)
            {
                scale = 1.8;
            }
            else if (75 < oal && oal <= 100)
            {
                scale = 1.4;
            }
            else
            {
                scale = 1;
            }

            oal = oal * scale;
            if (data.ContainsKey("tcpd"))
            {
                tcpd = Convert.ToDouble(data["tcpd"]) * scale;
            }
            if (data.ContainsKey("td"))
            {
                td = Convert.ToDouble(data["td"]) * scale;
            }
            if (data.ContainsKey("thl"))
            {
                thl = Convert.ToDouble(data["thl"]) * scale;
            }
            if (data.ContainsKey("tcl"))
            {
                tcl = Convert.ToDouble(data["tcl"]) * scale;
            }
            if (data.ContainsKey("dmm"))
            {
                dmm = Convert.ToDouble(data["dmm"]) * scale;
            }
            if (data.ContainsKey("path"))
            {
                path = Convert.ToString(data["path"]);
            }

            #endregion

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = fun.Polar(p0, 1.5 * pi, oal);  // 基准点 角度（弧度制） 距离
            Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
            Vector2 p6 = fun.Polar(p0p, 0, tcpd / 2);
            Vector2 p5 = new Vector2(p0p.X + td / 2, p0p.Y + tcl);
            Vector2 p4 = new Vector2(p5.X, p0p.Y + thl);
            Vector2 p3 = new Vector2(p6.X, p4.Y + (td - tcpd) / 2);
            Vector2 p2 = new Vector2(p3.X - (tcpd - dmm) / 2, p3.Y + (tcpd - dmm) / 2);
            Vector2 p7 = new Vector2(p0.X - p6.X, p6.Y);
            Vector2 p8 = new Vector2(p0.X - p5.X, p5.Y);
            Vector2 p9 = new Vector2(p0.X - p4.X, p4.Y);
            Vector2 p10 = new Vector2(p0.X - p3.X, p3.Y);
            Vector2 p11 = new Vector2(p0.X - p2.X, p2.Y);
            Vector2 p12 = new Vector2(p0.X - p1.X, p1.Y);

            Vector2 coc1 = fun.Polar(p2, 0, (td - dmm) / 4);  //圆弧圆心
            Vector2 coc2 = fun.Polar(p11, pi, (td - dmm) / 4);

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes[1].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p10));
            poly.Vertexes[9].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);  // dxf文件 多段线的名字 线宽 颜色

            Vector2[] dotline1 = { fun.Polar(p0, pi / 2, 2), fun.Polar(p0p, 1.5 * pi, 2) };
            fun.drawPlinetype(dxf, dotline1, 0.15, centre, Linetype.Center); //dxf文件 线段名字 颜色 线形
            Vector2[] xiline1 = { p7, p10 };
            fun.drawPlineOfw(dxf, xiline1, 0.15, additionalline);  //dxf文件 线段名字 线宽 颜色    
            Vector2[] xiline2 = { p6, p3 };
            fun.drawPlineOfw(dxf, xiline2, 0.15, additionalline);

            Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
            Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
            Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
            Vector2 p23 = new Vector2(p20.X, p22.Y);
            Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
            Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
            Vector2 p26 = new Vector2(p25.X, p23.Y);
            Vector2 p27 = new Vector2(p24.X, p23.Y);

            Vector2[] line3 = { p25, p26, p27, p24, p26 };
            fun.drawPline(dxf, line3, 0.15, contour);
            Vector2[] line4 = { p25, p27 };

            fun.drawPline(dxf, line4, 0.15, contour);
            Vector2[] line5 = { p21, p22, p23, p20, p22 };
            fun.drawPline(dxf, line5, 0.15, contour);
            Vector2[] line6 = { p21, p23 };
            fun.drawPline(dxf, line6, 0.15, contour);

            Vector2 p30 = new Vector2(p0.X - td / 8, p11.Y + (dmm - td / 2) / 2 + dmm / 8);
            Vector2 p31 = new Vector2(p30.X, p10.Y);
            Vector2 p32 = new Vector2(p30.X, p8.Y);
            Vector2 p33 = fun.Polar(p0p, pi, td / 16);
            Vector2 p34 = fun.Polar(p0p, 0, td / 8);
            Vector2 p35 = new Vector2(p34.X, p31.Y);
            Vector2 p36 = new Vector2(p34.X, p11.Y);
            Vector2 p37 = new Vector2(p1.X, p30.Y);

            LwPolyline poly1 = new LwPolyline();  //多段线
            poly1.Vertexes.Add(new LwPolylineVertex(p31));  //序号0
            poly1.Vertexes.Add(new LwPolylineVertex(p30));  //序号1
            poly1.Vertexes[1].Bulge = Math.Tan(pi / 10);  //圆弧 凸度=圆心角的四分之一的正切值 
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p37));
            poly2.Vertexes[0].Bulge = Math.Tan(pi / 10);
            poly2.Vertexes.Add(new LwPolylineVertex(p36));
            poly2.Vertexes.Add(new LwPolylineVertex(p35));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p31));
            poly3.Vertexes.Add(new LwPolylineVertex(p32));
            poly3.Vertexes.Add(new LwPolylineVertex(p33));
            poly3.Vertexes.Add(new LwPolylineVertex(p34));
            poly3.Vertexes.Add(new LwPolylineVertex(p35));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;

            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);  //  dxf type numst 填充线段的间距 填充线段的角度 line 图层颜色
            fun.PolyFill(dxf, poly3, 0.3, contour);

            //标注 箭头参数
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 2.5;
            double offset = 15;
            //标注
            LinearDimension dim1 = new LinearDimension(new Line(p7, p12), offset * 2, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim1, oal / scale);

            LinearDimension dim2 = new LinearDimension(new Line(p7, p9), offset, 90, dimensionStyle);
            fun.dxflinedim(dxf, dim2, thl / scale);

            LinearDimension dim3 = new LinearDimension(new Line(p1, p12), offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, dim3, dmm / scale);

            LinearDimension dim4 = new LinearDimension(new Line(p5, p6), offset, 270, dimensionStyle);
            fun.dxflinedim(dxf, dim4, tcl / scale);

            LinearDimension dim5 = new LinearDimension(new Line(p6, p7), offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim5, tcpd / scale);

            LinearDimension dim6 = new LinearDimension(new Line(p5, p8), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, dim6, td / scale);

            double isframe = Convert.ToDouble(data["isframe"]);
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 225, p0.Y + 50), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }


        public static void ThreadCuttingTapWithOffsetShank(Dictionary<string, Object> data)  //细柄切削丝锥 
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            double pi = Math.PI;

            double sl = Convert.ToDouble(data["oal"]);
            double scale;
            if (sl <= 50)
            {
                scale = 5;
            }
            else if (50 < sl && sl <= 75)
            {
                scale = 4;
            }
            else if (75 < sl && sl <= 100)
            {
                scale = 3;
            }
            else
            {
                scale = 1.2;
            }

            double oal = Convert.ToDouble(data["oal"]) * scale;
            double tp = Convert.ToDouble(data["tp"]) * scale;
            double td = Convert.ToDouble(data["td"]) * scale;
            double tcpd = td - tp;
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double tcl = tp * 1.5;
            double dmm = Convert.ToDouble(data["dmm"]) * scale;
            double TSYC = Convert.ToDouble(data["tsyc"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);

            Vector2 p0 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p0p = fun.Polar(p0, pi, oal);  // 基准点 角度（弧度制） 距离
            Vector2 p1 = fun.Polar(p0, 1.5 * pi, dmm / 2);
            Vector2 p6 = fun.Polar(p0p, 1.5 * pi, tcpd / 2);
            Vector2 p5 = new Vector2(p0p.X + tcl, p0p.Y - td / 2);
            // Vector2 p4 = new Vector2(p5.X, p0p.Y + thl);
            // Vector2 p3 = new Vector2(p6.X, p4.Y + (td - tcpd) / 2);
            // Vector2 p2 = new Vector2(p3.X - (tcpd - dmm) / 2, p3.Y + (tcpd - dmm) / 2);

            Vector2 p4 = new Vector2(p0p.X + thl, p5.Y);
            Vector2 p3 = new Vector2(p4.X + (td - tcpd) / 2, p6.Y);
            Vector2 p2 = new Vector2(p3.X + (tcpd - dmm) / 2, p3.Y + (tcpd - dmm) / 2);

            Vector2 p7 = new Vector2(p0.X - p6.X, p6.Y);
            Vector2 p8 = new Vector2(p0.X - p5.X, p5.Y);
            Vector2 p9 = new Vector2(p0.X - p4.X, p4.Y);
            Vector2 p10 = new Vector2(p0.X - p3.X, p3.Y);
            Vector2 p11 = new Vector2(p0.X - p2.X, p2.Y);
            Vector2 p12 = new Vector2(p0.X - p1.X, p1.Y);

            p7 = new Vector2(p6.X, p0.Y - p6.Y);
            p8 = new Vector2(p5.X, p0.Y - p5.Y);
            p9 = new Vector2(p4.X, p0.Y - p4.Y);
            p10 = new Vector2(p3.X, p0.Y - p3.Y);
            p11 = new Vector2(p2.X, p0.Y - p2.Y);
            p12 = new Vector2(p1.X, p0.Y - p1.Y);

            //Vector2 coc1 = fun.Polar(p2, 0, (td - dmm) / 4);  //圆弧圆心
            //Vector2 coc2 = fun.Polar(p11, pi, (td - dmm) / 4);

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes[1].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p10));
            poly.Vertexes[9].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);  // dxf文件 多段线的名字 线宽 颜色

            Vector2[] dotline1 = { fun.Polar(p0, 0, 2), fun.Polar(p0p, pi, 2) };
            fun.drawPlinetype(dxf, dotline1, 0.15, centre, Linetype.Center); //dxf文件 线段名字 颜色 线形

            // Vector2[] xiline1 = { p7, p10 };
            // fun.drawPlineOfw(dxf, xiline1, 0.1, additionalline);  //dxf文件 线段名字 线宽 颜色
            // Vector2[] xiline2 = { p6, p3 };
            // fun.drawPlineOfw(dxf, xiline2, 0.1, additionalline);

            //柄方
            Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
            Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
            Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
            Vector2 p23 = new Vector2(p20.X, p22.Y);

            p20 = fun.Polar(p0, 1.5 * pi, dmm / 10);
            p21 = fun.Polar(p20, 1.5 * pi, dmm * 0.3);
            p22 = fun.Polar(p21, pi, oal / 10);
            p23 = new Vector2(p22.X, p20.Y);

            Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
            Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
            Vector2 p26 = new Vector2(p25.X, p23.Y);
            Vector2 p27 = new Vector2(p24.X, p23.Y);
            p24 = fun.Polar(p0, 0.5 * pi, dmm / 10);
            p25 = fun.Polar(p24, 0.5 * pi, dmm * 0.3);
            p26 = new Vector2(p23.X, p25.Y);
            p27 = new Vector2(p23.X, p24.Y);

            Vector2[] line3 = { p25, p26, p27, p24, p26 };
            fun.drawPline(dxf, line3, 0.15, contour);
            Vector2[] line4 = { p25, p27 };
            fun.drawPline(dxf, line4, 0.15, contour);
            Vector2[] line5 = { p21, p22, p23, p20, p22 };
            fun.drawPline(dxf, line5, 0.15, contour);
            Vector2[] line6 = { p21, p23 };
            fun.drawPline(dxf, line6, 0.15, contour);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p7));
            poly3.Vertexes.Add(new LwPolylineVertex(p10));
            poly3.Vertexes.Add(new LwPolylineVertex(p3));
            poly3.Vertexes.Add(new LwPolylineVertex(p6));
            poly3.SetConstantWidth(0.1);
            poly3.IsClosed = true;

            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 85, 20, line, cutting);
            fun.PolyFill(dxf, poly3, 0.3, contour);
            /*
                        Vector2 p30 = new Vector2(p0.X - td / 8, p11.Y + (dmm - td / 2) / 2 + dmm / 8);
                        Vector2 p31 = new Vector2(p30.X, p10.Y);
                        Vector2 p32 = new Vector2(p30.X, p8.Y);
                        Vector2 p33 = fun.Polar(p0p, pi, td / 16);
                        Vector2 p34 = fun.Polar(p0p, 0, td / 8);
                        Vector2 p35 = new Vector2(p34.X, p31.Y);
                        Vector2 p36 = new Vector2(p34.X, p11.Y);
                        Vector2 p37 = new Vector2(p1.X, p30.Y);

                        p30 = new Vector2(p11.X + (dmm - td / 2) / 2 + dmm / 8, p0.Y + td / 8);
                        p31 = new Vector2(p10.X, p30.Y);
                        p32 = new Vector2(p8.X, p30.Y);
                        p33 = fun.Polar(p0p, 0.5 * pi, td / 16);
                        p34 = fun.Polar(p0p, 1.5 * pi, td / 8);
                        p35 = new Vector2(p31.X, p34.Y);
                        p36 = new Vector2(p11.X, p34.Y);
                        p37 = new Vector2(p30.X, p1.Y);

                        LwPolyline poly1 = new LwPolyline();
                        poly1.Vertexes.Add(new LwPolylineVertex(p31));
                        poly1.Vertexes.Add(new LwPolylineVertex(p30));
                        poly1.Vertexes[1].Bulge = Math.Tan(pi / 10);
                        poly1.Vertexes.Add(new LwPolylineVertex(p11));
                        fun.PolyFill(dxf, poly1, 0.3, contour);
                        LwPolyline poly2 = new LwPolyline();
                        poly2.Vertexes.Add(new LwPolylineVertex(p37));
                        poly2.Vertexes[0].Bulge = Math.Tan(pi / 10);
                        poly2.Vertexes.Add(new LwPolylineVertex(p36));
                        poly2.Vertexes.Add(new LwPolylineVertex(p35));
                        fun.PolyFill(dxf, poly2, 0.3, contour);

                        LwPolyline poly3 = new LwPolyline();
                        poly3.Vertexes.Add(new LwPolylineVertex(p31));
                        poly3.Vertexes.Add(new LwPolylineVertex(p32));
                        poly3.Vertexes.Add(new LwPolylineVertex(p33));
                        poly3.Vertexes.Add(new LwPolylineVertex(p34));
                        poly3.Vertexes.Add(new LwPolylineVertex(p35));
                        poly3.SetConstantWidth(0.3);
                        poly3.IsClosed = true;

                        String[] type = new String[100];
                        Line[] line = new Line[100];
                        int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
                        for (int i = 0; i < numst; i++)
                        {
                            type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                            if (type[i] == "Line")
                            {
                                line[i] = (Line)poly3.Explode()[i];
                            }
                        }
                        fun.hatchsubofline(dxf, type, numst, 85, 20, line, hatching);
                        fun.PolyFill(dxf, poly3, 0.3, contour);
                      */
            //标注 箭头参数
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 2.5;
            double offset = 20;
            //标注
            if (TSYC == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(p7, p12), offset * 2, 0, dimensionStyle);
                dim1.UserText = "OAL";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p7, p9), offset, 0, dimensionStyle);
                dim2.UserText = "THL";
                dxf.AddEntity(dim2);

                LinearDimension dim3 = new LinearDimension(new Line(p1, p12), offset, 270, dimensionStyle);
                dim3.UserText = "DMM";
                dxf.AddEntity(dim3);

                LinearDimension dim4 = new LinearDimension(new Line(p5, p6), offset, 180, dimensionStyle);
                dim4.UserText = "TCL";
                dxf.AddEntity(dim4);

                LinearDimension dim5 = new LinearDimension(new Line(p6, p7), offset, 90, dimensionStyle);
                dim5.UserText = "TCPD";
                dxf.AddEntity(dim5);

                LinearDimension dim6 = new LinearDimension(new Line(p5, p8), offset * 2, 90, dimensionStyle);
                dim6.UserText = "TD";
                dxf.AddEntity(dim6);
            }
            else
            {
                LinearDimension dim1 = new LinearDimension(new Line(p7, p12), offset * 2, 0, dimensionStyle);
                dim1.UserText = String.Format("{0}", oal / scale);
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p7, p9), offset, 0, dimensionStyle);
                dim2.UserText = String.Format("{0}", thl / scale);
                dxf.AddEntity(dim2);

                LinearDimension dim3 = new LinearDimension(new Line(p1, p12), offset, 270, dimensionStyle);
                dim3.UserText = String.Format("{0}", dmm / scale);
                dxf.AddEntity(dim3);

                LinearDimension dim4 = new LinearDimension(new Line(p5, p6), offset, 180, dimensionStyle);
                dim4.UserText = String.Format("{0}", tcl / scale);
                dxf.AddEntity(dim4);

                LinearDimension dim5 = new LinearDimension(new Line(p6, p7), offset, 90, dimensionStyle);
                dim5.UserText = String.Format("{0}", tcpd / scale);
                dxf.AddEntity(dim5);

                LinearDimension dim6 = new LinearDimension(new Line(p5, p8), offset * 2, 90, dimensionStyle);
                dim6.UserText = String.Format("{0}", td / scale);
                dxf.AddEntity(dim6);
            }
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 210 + oal / 2, p0.Y + 148.5), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void ThreadCuttingTapWithReinforcedShank(Dictionary<string, Object> data)  //粗柄切削丝锥
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层

            double pi = Math.PI;
            double sl = Convert.ToDouble(data["oal"]);
            double scale;
            if (sl <= 50)
            {
                scale = 4;
            }
            else if (50 < sl && sl <= 75)
            {
                scale = 3.2;
            }
            else if (75 < sl && sl <= 100)
            {
                scale = 2.5;
            }
            else
            {
                scale = 1.5;
            }

            double oal = Convert.ToDouble(data["oal"]) * scale;
            double tcpd = Convert.ToDouble(data["tcpd"]) * scale;
            double td = Convert.ToDouble(data["td"]) * scale;
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double tcpl = Convert.ToDouble(data["tcpl"]) * scale;
            double dmm = Convert.ToDouble(data["dmm"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double dn = Convert.ToDouble(data["dn"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //double fha = Convert.ToDouble(data["fha"]) * scale;
            string path = Convert.ToString(data["path"]);

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X, p0.Y - oal);
            Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
            Vector2 p2 = fun.Polar(p1, 1.5 * pi, ls);
            Vector2 p3 = new Vector2(p0.X + dn / 2, p0p.Y + lu);
            Vector2 p4 = new Vector2(p3.X, p0p.Y + thl + 0.5);
            Vector2 p5 = new Vector2(p0.X + td / 2, p0p.Y + thl);
            Vector2 p6 = new Vector2(p0.X + td / 2, p0p.Y + tcpl);
            Vector2 p7 = new Vector2(p0.X + tcpd / 2, p0p.Y);
            Vector2 p8 = new Vector2(p0.X - p7.X, p7.Y);
            Vector2 p9 = new Vector2(p0.X - p6.X, p6.Y);
            Vector2 p10 = new Vector2(p0.X - p5.X, p5.Y);
            Vector2 p11 = new Vector2(p0.X - p4.X, p4.Y);
            Vector2 p12 = new Vector2(p0.X - p3.X, p3.Y);
            Vector2 p13 = new Vector2(p0.X - p2.X, p2.Y);
            Vector2 p14 = new Vector2(p0.X - p1.X, p1.Y);

            Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
            Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
            Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
            Vector2 p23 = new Vector2(p20.X, p22.Y);
            Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
            Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
            Vector2 p26 = new Vector2(p25.X, p23.Y);
            Vector2 p27 = new Vector2(p24.X, p23.Y);

            p0p = fun.rotatePoint(p0p);
            p1 = fun.Polar(p0, 1.5 * pi, dmm / 2);
            p2 = fun.rotatePoint(p2);
            p3 = fun.rotatePoint(p3);
            p4 = fun.rotatePoint(p4);
            p5 = fun.rotatePoint(p5);
            p6 = fun.rotatePoint(p6);
            p7 = fun.rotatePoint(p7);
            p8 = fun.rotatePoint(p8);
            p9 = fun.rotatePoint(p9);
            p10 = fun.rotatePoint(p10);
            p11 = fun.rotatePoint(p11);
            p12 = fun.rotatePoint(p12);
            p13 = fun.rotatePoint(p13);
            p14 = fun.rotatePoint(p14);

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p10));
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            poly1.Vertexes.Add(new LwPolylineVertex(p12));
            poly1.Vertexes.Add(new LwPolylineVertex(p13));
            poly1.Vertexes.Add(new LwPolylineVertex(p14));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            Line dotline1 = new Line(fun.Polar(p0, 0, 2), fun.Polar(p0p, pi, 2));
            dotline1.Linetype = Linetype.Center;
            dotline1.Layer = centre;
            dxf.AddEntity(dotline1);

            p20 = fun.rotatePoint(p20);
            p21 = fun.rotatePoint(p21);
            p22 = fun.rotatePoint(p22);
            p23 = fun.rotatePoint(p23);
            p24 = fun.rotatePoint(p24);
            p25 = fun.rotatePoint(p25);
            p26 = fun.rotatePoint(p26);
            p27 = fun.rotatePoint(p27);

            Vector2[] line3 = { p25, p26, p27, p24, p26 };
            fun.drawPline(dxf, line3, 0.15, contour);
            Vector2[] line4 = { p25, p27 };
            fun.drawPline(dxf, line4, 0.15, contour);
            Vector2[] line5 = { p21, p22, p23, p20, p22 };
            fun.drawPline(dxf, line5, 0.15, contour);
            Vector2[] line6 = { p21, p23 };
            fun.drawPline(dxf, line6, 0.15, contour);

            Vector2[] line7 = { p2, p13 };
            fun.drawPlineOfw(dxf, line7, 0.3, contour);
            Vector2[] line8 = { p3, p12 };
            fun.drawPlineOfw(dxf, line8, 0.3, contour);
            Vector2[] line9 = { p4, p11 };
            fun.drawPlineOfw(dxf, line9, 0.3, contour);
            Vector2[] line10 = { p5, p10 };
            fun.drawPlineOfw(dxf, line10, 0.3, contour);

            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(p10));
            poly4.Vertexes.Add(new LwPolylineVertex(p9));
            poly4.Vertexes.Add(new LwPolylineVertex(p8));
            poly4.Vertexes.Add(new LwPolylineVertex(p7));
            poly4.Vertexes.Add(new LwPolylineVertex(p6));
            poly4.Vertexes.Add(new LwPolylineVertex(p5));
            poly4.IsClosed = true;

            String[] type4 = new String[100];
            Line[] pline4 = new Line[100];
            int numLIne4 = poly4.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numLIne4; i++)
            {
                type4[i] = poly4.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type4[i] == "Line")
                {
                    pline4[i] = (Line)poly4.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type4, numLIne4, 85, 8 * scale, pline4, cutting);

            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 2.5;
            double offset = 20;

            LinearDimension linedim1 = new LinearDimension(new Line(p8, p14), offset * 3, 0, dimensionStyle);
            linedim1.UserText = String.Format("{0}", oal / scale);
            dxf.AddEntity(linedim1);

            LinearDimension linedim2 = new LinearDimension(new Line(p10, p8), offset, 0, dimensionStyle);
            linedim2.UserText = String.Format("{0}", thl / scale);
            dxf.AddEntity(linedim2);

            LinearDimension linedim3 = new LinearDimension(new Line(p1, p14), offset, 270, dimensionStyle);
            linedim3.UserText = String.Format("{0}", dmm / scale);
            dxf.AddEntity(linedim3);

            LinearDimension linedim4 = new LinearDimension(new Line(p14, p13), offset, 0, dimensionStyle);
            linedim4.UserText = String.Format("{0}", ls / scale);
            dxf.AddEntity(linedim4);

            LinearDimension linedim5 = new LinearDimension(new Line(p7, p8), offset, 90, dimensionStyle);
            linedim5.UserText = String.Format("{0}", tcpd / scale);
            dxf.AddEntity(linedim5);

            LinearDimension linedim6 = new LinearDimension(new Line(p6, p9), offset * 2, 90, dimensionStyle);
            linedim6.UserText = String.Format("{0}", td / scale);
            dxf.AddEntity(linedim6);

            LinearDimension linedim7 = new LinearDimension(new Line(p8, p12), offset * 2, 0, dimensionStyle);
            linedim6.UserText = String.Format("{0}", lu / scale);
            dxf.AddEntity(linedim7);

            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 210 + oal / 2, p0.Y + 148.5), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void ThreadFormingTapWithOffsetShank(Dictionary<string, Object> data)  //细柄挤压丝锥
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            double pi = Math.PI;

            double sl = Convert.ToDouble(data["oal"]);
            double scale;
            if (sl <= 50)
            {
                scale = 2.2;
            }
            else if (50 < sl && sl <= 75)
            {
                scale = 1.8;
            }
            else if (75 < sl && sl <= 100)
            {
                scale = 1.4;
            }
            else
            {
                scale = 1;
            }

            double oal = Convert.ToDouble(data["oal"]) * scale;
            double tcpd = Convert.ToDouble(data["tcpd"]) * scale;
            double dmm = Convert.ToDouble(data["dconms"]) * scale;
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double tcl = Convert.ToDouble(data["tcl"]) * scale;
            double td = Convert.ToDouble(data["td"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X, p0.Y - oal);
            Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
            Vector2 p2 = fun.Polar(p1, 1.5 * pi, oal - thl - (td - tcpd) / 2);
            Vector2 p3 = new Vector2(p0.X + td / 2, p0.Y - (oal - thl));
            Vector2 p4 = new Vector2(p0.X + td / 2, p0p.Y + tcl);
            Vector2 p5 = fun.Polar(p0p, 0, tcpd / 2);
            Vector2 p6 = new Vector2(p0.X - p5.X, p5.Y);
            Vector2 p7 = new Vector2(p0.X - p4.X, p4.Y);
            Vector2 p8 = new Vector2(p0.X - p3.X, p3.Y);
            Vector2 p9 = new Vector2(p0.X - p2.X, p2.Y);
            Vector2 p10 = new Vector2(p0.X - p1.X, p1.Y);

            Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
            Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
            Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
            Vector2 p23 = new Vector2(p20.X, p22.Y);
            Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
            Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
            Vector2 p26 = new Vector2(p25.X, p23.Y);
            Vector2 p27 = new Vector2(p24.X, p23.Y);

            Vector2 p30 = new Vector2(p0.X - tcpd / 6, p2.Y + tcpd / 3);
            Vector2 p31 = new Vector2(p30.X, p2.Y);
            Vector2 p32 = new Vector2(p30.X, p5.Y);
            Vector2 p33 = new Vector2(p0.X - p32.X, p32.Y);
            Vector2 p34 = new Vector2(p0.X - p31.X, p31.Y);
            Vector2 p35 = new Vector2(p0.X - p30.X, p30.Y);

            p0p = fun.rotatePoint(p0p);
            p1 = fun.rotatePoint(p1);
            p2 = fun.rotatePoint(p2);
            p3 = fun.rotatePoint(p3);
            p4 = fun.rotatePoint(p4);
            p5 = fun.rotatePoint(p5);
            p6 = fun.rotatePoint(p6);
            p7 = fun.rotatePoint(p7);
            p8 = fun.rotatePoint(p8);
            p9 = fun.rotatePoint(p9);
            p10 = fun.rotatePoint(p10);

            p20 = fun.rotatePoint(p20);
            p21 = fun.rotatePoint(p21);
            p22 = fun.rotatePoint(p22);
            p23 = fun.rotatePoint(p23);
            p24 = fun.rotatePoint(p24);
            p25 = fun.rotatePoint(p25);
            p26 = fun.rotatePoint(p26);
            p27 = fun.rotatePoint(p27);

            p30 = fun.rotatePoint(p30);
            p31 = fun.rotatePoint(p31);
            p32 = fun.rotatePoint(p32);
            p33 = fun.rotatePoint(p33);
            p34 = fun.rotatePoint(p34);
            p35 = fun.rotatePoint(p35);

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p10));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            Line dotline1 = new Line(fun.Polar(p0, 0, 2), fun.Polar(p0p, pi, 2));
            dotline1.Linetype = Linetype.Center;
            dotline1.Layer = center;
            dxf.AddEntity(dotline1);

            Vector2[] line3 = { p25, p26, p27, p24, p26 };
            fun.drawPline(dxf, line3, 0.15, contour);
            Vector2[] line4 = { p25, p27 };
            fun.drawPline(dxf, line4, 0.15, contour);
            Vector2[] line5 = { p21, p22, p23, p20, p22 };
            fun.drawPline(dxf, line5, 0.15, contour);
            Vector2[] line6 = { p21, p23 };
            fun.drawPline(dxf, line6, 0.15, contour);

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p33));
            poly2.Vertexes.Add(new LwPolylineVertex(p35));
            poly2.Vertexes[1].Bulge = 1;
            poly2.Vertexes.Add(new LwPolylineVertex(p30));
            poly2.Vertexes.Add(new LwPolylineVertex(p32));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            Vector2[] line7 = { p9, p31 };
            fun.drawPlineOfw(dxf, line7, 0.3, contour);
            Vector2[] line8 = { p2, p34 };
            fun.drawPlineOfw(dxf, line8, 0.3, contour);

            Vector2[] xiline1 = { p2, p5 };
            fun.drawPline(dxf, xiline1, 0.15, contour);
            Vector2[] xiline2 = { p6, p9 };
            fun.drawPline(dxf, xiline2, 0.15, contour);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p6));
            poly3.Vertexes.Add(new LwPolylineVertex(p7));
            poly3.Vertexes.Add(new LwPolylineVertex(p8));
            poly3.Vertexes.Add(new LwPolylineVertex(p9));
            poly3.Vertexes.Add(new LwPolylineVertex(p31));
            poly3.Vertexes.Add(new LwPolylineVertex(p32));
            poly3.IsClosed = true;

            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 85, 20, line, cutting);

            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(p2));
            poly4.Vertexes.Add(new LwPolylineVertex(p3));
            poly4.Vertexes.Add(new LwPolylineVertex(p4));
            poly4.Vertexes.Add(new LwPolylineVertex(p5));
            poly4.Vertexes.Add(new LwPolylineVertex(p33));
            poly4.Vertexes.Add(new LwPolylineVertex(p34));
            poly4.IsClosed = true;

            String[] type4 = new String[100];
            Line[] pline4 = new Line[100];
            int numst4 = poly4.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst4; i++)
            {
                type4[i] = poly4.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type4[i] == "Line")
                {
                    pline4[i] = (Line)poly4.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type4, numst4, 85, 20, pline4, cutting);

            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 3.5;
            double offset = 20;

            LinearDimension linedim1 = new LinearDimension(new Line(p6, p10), offset * 3, 0, dimensionStyle);
            linedim1.UserText = String.Format("{0}", oal / scale);
            dxf.AddEntity(linedim1);

            LinearDimension linedim2 = new LinearDimension(new Line(p6, p8), offset, 0, dimensionStyle);
            linedim2.UserText = String.Format("{0}", thl / scale);
            dxf.AddEntity(linedim2);

            LinearDimension linedim3 = new LinearDimension(new Line(p1, p10), offset, 270, dimensionStyle);
            linedim3.UserText = String.Format("{0}", dmm / scale);
            dxf.AddEntity(linedim3);

            LinearDimension linedim4 = new LinearDimension(new Line(p4, p5), offset, 180, dimensionStyle);
            linedim4.UserText = String.Format("{0}", tcl / scale);
            dxf.AddEntity(linedim4);

            LinearDimension linedim5 = new LinearDimension(new Line(p5, p6), offset, 90, dimensionStyle);
            linedim5.UserText = String.Format("{0}", tcpd / scale);
            dxf.AddEntity(linedim5);

            LinearDimension linedim6 = new LinearDimension(new Line(p4, p7), offset * 2, 90, dimensionStyle);
            linedim6.UserText = String.Format("{0}", td / scale);
            dxf.AddEntity(linedim6);

            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 210 - oal / 2, p0.Y + 148.5), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);

            fun.SetByLayer(dxf);
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void ThreadFormingTapWithReinforcedShank(Dictionary<string, Object> data)  //粗柄挤压丝锥
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            double pi = Math.PI;

            double sl = Convert.ToDouble(data["oal"]);
            double scale;
            if (sl <= 50)
            {
                scale = 2.2;
            }
            else if (50 < sl && sl <= 75)
            {
                scale = 1.8;
            }
            else if (75 < sl && sl <= 100)
            {
                scale = 1.4;
            }
            else
            {
                scale = 1;
            }

            double oal = Convert.ToDouble(data["oal"]) * scale;
            double tcpd = Convert.ToDouble(data["tcpd"]) * scale;
            double dmm = Convert.ToDouble(data["dconms"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double tcl = Convert.ToDouble(data["tcl"]) * scale;
            double td = Convert.ToDouble(data["td"]) * scale;
            double dn = Convert.ToDouble(data["dn"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //double fha = Convert.ToDouble(data["fha"]);
            string path = Convert.ToString(data["path"]);

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X, p0.Y - oal);
            Vector2 p1 = fun.Polar(p0, 0, dmm / 2);
            Vector2 p2 = fun.Polar(p1, 1.5 * pi, ls);
            Vector2 p3 = new Vector2(p0.X + dn / 2, p0p.Y + lu);
            Vector2 p4 = new Vector2(p3.X, p0p.Y + thl + 0.5);
            Vector2 p5 = new Vector2(p0.X + tcpd / 2, p0p.Y + thl);
            Vector2 p6 = new Vector2(p0.X + td / 2, p5.Y);
            Vector2 p7 = new Vector2(p6.X, p0p.Y + tcl);
            Vector2 p8 = fun.Polar(p0p, 0, tcpd / 2);
            Vector2 p9 = new Vector2(p0.X - p8.X, p8.Y);
            Vector2 p10 = new Vector2(p0.X - p7.X, p7.Y);
            Vector2 p11 = new Vector2(p0.X - p6.X, p6.Y);
            Vector2 p12 = new Vector2(p0.X - p5.X, p5.Y);
            Vector2 p13 = new Vector2(p0.X - p4.X, p4.Y);
            Vector2 p14 = new Vector2(p0.X - p3.X, p3.Y);
            Vector2 p15 = new Vector2(p0.X - p2.X, p2.Y);
            Vector2 p16 = new Vector2(p0.X - p1.X, p1.Y);

            Vector2 p20 = fun.Polar(p0, 0, dmm / 10);
            Vector2 p21 = fun.Polar(p20, 0, dmm * 0.3);
            Vector2 p22 = fun.Polar(p21, 1.5 * pi, oal / 10);
            Vector2 p23 = new Vector2(p20.X, p22.Y);
            Vector2 p24 = fun.Polar(p0, pi, dmm / 10);
            Vector2 p25 = fun.Polar(p24, pi, dmm * 0.3);
            Vector2 p26 = new Vector2(p25.X, p23.Y);
            Vector2 p27 = new Vector2(p24.X, p23.Y);

            p0p = fun.rotatePoint(p0p);
            p1 = fun.rotatePoint(p1);
            p2 = fun.rotatePoint(p2);
            p3 = fun.rotatePoint(p3);
            p4 = fun.rotatePoint(p4);
            p5 = fun.rotatePoint(p5);
            p6 = fun.rotatePoint(p6);
            p7 = fun.rotatePoint(p7);
            p8 = fun.rotatePoint(p8);
            p9 = fun.rotatePoint(p9);
            p10 = fun.rotatePoint(p10);
            p11 = fun.rotatePoint(p11);
            p12 = fun.rotatePoint(p12);
            p13 = fun.rotatePoint(p13);
            p14 = fun.rotatePoint(p14);
            p15 = fun.rotatePoint(p15);
            p16 = fun.rotatePoint(p16);

            p20 = fun.rotatePoint(p20);
            p21 = fun.rotatePoint(p21);
            p22 = fun.rotatePoint(p22);
            p23 = fun.rotatePoint(p23);
            p24 = fun.rotatePoint(p24);
            p25 = fun.rotatePoint(p25);
            p26 = fun.rotatePoint(p26);
            p27 = fun.rotatePoint(p27);

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p10));
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            poly1.Vertexes.Add(new LwPolylineVertex(p12));
            poly1.Vertexes.Add(new LwPolylineVertex(p13));
            poly1.Vertexes.Add(new LwPolylineVertex(p14));
            poly1.Vertexes.Add(new LwPolylineVertex(p15));
            poly1.Vertexes.Add(new LwPolylineVertex(p16));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            Line dotline1 = new Line(fun.Polar(p0, 0, 2), fun.Polar(p0p, pi, 2));
            dotline1.Linetype = Linetype.Center;
            dotline1.Layer = center;
            dxf.AddEntity(dotline1);

            Vector2[] line3 = { p25, p26, p27, p24, p26 };
            fun.drawPline(dxf, line3, 0.15, contour);
            Vector2[] line4 = { p25, p27 };
            fun.drawPline(dxf, line4, 0.15, contour);
            Vector2[] line5 = { p21, p22, p23, p20, p22 };
            fun.drawPline(dxf, line5, 0.15, contour);
            Vector2[] line6 = { p21, p23 };
            fun.drawPline(dxf, line6, 0.15, contour);

            Vector2[] line7 = { p2, p15 };
            fun.drawPlineOfw(dxf, line7, 0.3, contour);
            Vector2[] line8 = { p3, p14 };
            fun.drawPlineOfw(dxf, line8, 0.3, contour);
            Vector2[] line9 = { p4, p13 };
            fun.drawPlineOfw(dxf, line9, 0.3, contour);
            Vector2[] line10 = { p5, p12 };
            fun.drawPlineOfw(dxf, line10, 0.3, contour);

            Vector2[] xiline1 = { p5, p8 };
            fun.drawPline(dxf, xiline1, 0.15, contour);
            Vector2[] xiline2 = { p9, p12 };
            fun.drawPline(dxf, xiline2, 0.15, contour);

            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p6));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p7));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p8));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p10));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p11));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 85, 20, hline1, cutting);

            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 1.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 2.5;
            double offset = 20;

            LinearDimension linedim1 = new LinearDimension(new Line(p16, p9), offset * 3, 0, dimensionStyle);
            linedim1.UserText = String.Format("{0}", oal / scale);
            dxf.AddEntity(linedim1);

            LinearDimension linedim2 = new LinearDimension(new Line(p15, p16), offset, 0, dimensionStyle);
            linedim2.UserText = String.Format("{0}", ls / scale);
            dxf.AddEntity(linedim2);

            LinearDimension linedim3 = new LinearDimension(new Line(p9, p14), offset * 2, 0, dimensionStyle);
            linedim3.UserText = String.Format("{0}", lu / scale);
            dxf.AddEntity(linedim3);

            LinearDimension linedim4 = new LinearDimension(new Line(p9, p11), offset, 0, dimensionStyle);
            linedim4.UserText = String.Format("{0}", thl / scale);
            dxf.AddEntity(linedim4);

            LinearDimension linedim5 = new LinearDimension(new Line(p1, p16), offset, 270, dimensionStyle);
            linedim5.UserText = String.Format("{0}", dmm / scale);
            dxf.AddEntity(linedim5);

            LinearDimension linedim6 = new LinearDimension(new Line(p7, p8), offset, 180, dimensionStyle);
            linedim6.UserText = String.Format("{0}", tcl / scale);
            dxf.AddEntity(linedim6);

            LinearDimension linedim7 = new LinearDimension(new Line(p8, p9), offset, 90, dimensionStyle);
            linedim7.UserText = String.Format("{0}", tcpd / scale);
            dxf.AddEntity(linedim7);

            LinearDimension linedim8 = new LinearDimension(new Line(p7, p10), offset * 2, 90, dimensionStyle);
            linedim8.UserText = String.Format("{0}", td / scale);
            dxf.AddEntity(linedim8);

            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 210 - oal / 2, p0.Y + 148.5), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            fun.SetLayer(dxf);

            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void ThreadCuttingDieRoundShape(Dictionary<string, Object> data)  //圆板牙
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;

            double pi = Math.PI;

            double oal = Convert.ToDouble(data["oal"]);
            double bd = Convert.ToDouble(data["bd"]);
            double td = Convert.ToDouble(data["td"]);
            double tdn = Convert.ToDouble(data["tdn"]);
            double tdz = Convert.ToDouble(data["tdz"]);
            double ddch = Convert.ToDouble(data["ddch"]);
            double ddchc = Convert.ToDouble(data["ddchc"]);
            //double dchc = Convert.ToDouble(data["dchc"]);
            string path = Convert.ToString(data["path"]);



            /*
            double oal = 12;
            double bd = 30;
            double td = 7;
            double tdn = 6;
            double tdz = 8;
            double ddch = 10;
            double ddchc =15;
            double DIM = 1;
            //double dchc = Convert.ToDouble(data["dchc"]);
            string path = Convert.ToString(data["path"]);
            */



            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.8;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 3.5;
            double offset = 7;
            Vector2 p00 = new Vector2(0, 0);
            Vector2 p01 = fun.Polar(p00, pi / 2, bd);
            Vector2 p02 = fun.Polar(p00, pi / 2, bd / 2);
            Vector2 p1 = fun.Polar(p02, pi * 1.5 + pi / 3.0 - Math.Acos((ddchc * ddchc + tdn * tdn - ddch * ddch) / (2.0 * ddchc * tdn)), tdn / 2);
            Vector2 p2 = fun.Polar(p02, pi * 1.5 - pi / 3.0 + Math.Acos((ddchc * ddchc + tdn * tdn - ddch * ddch) / (2.0 * ddchc * tdn)), tdn / 2);
            Vector2 p3 = fun.Polar(p02, pi * 1.5 - pi / 3.0 - Math.Acos((ddchc * ddchc + tdn * tdn - ddch * ddch) / (2.0 * ddchc * tdn)), tdn / 2);
            Vector2 p4 = fun.Polar(p02, pi * 0.5 + Math.Acos((ddchc * ddchc + tdn * tdn - ddch * ddch) / (2.0 * ddchc * tdn)), tdn / 2);
            //Console.WriteLine(Math.Acos((ddchc * ddchc + tdn * tdn - ddch * ddch) / (2.0 * ddchc * tdn)) * 180 / pi);
            //Console.ReadKey();
            Vector2 p5 = fun.Polar(p02, pi * 0.5 - Math.Acos((ddchc * ddchc + tdn * tdn - ddch * ddch) / (2.0 * ddchc * tdn)), tdn / 2);
            Vector2 p6 = fun.Polar(p02, pi * 1.5 + pi / 3.0 + Math.Acos((ddchc * ddchc + tdn * tdn - ddch * ddch) / (2.0 * ddchc * tdn)), tdn / 2);
            Vector2 p13 = fun.Polar(p02, pi / 3 + 1.5 * pi, ddchc / 2);
            Vector2 p14 = fun.Polar(p02, pi / 6 + pi, ddchc / 2);
            Vector2 p15 = fun.Polar(p02, pi / 2, ddchc / 2);
            Vector2 p133 = fun.Polar(p02, pi / 3 + 1.5 * pi, tdz / 2);
            Vector2 p144 = fun.Polar(p02, pi / 6 + pi, tdz / 2);
            Vector2 p155 = fun.Polar(p02, pi / 2, tdz / 2);
            Arc arc1 = fun.DrawArc(p1, p13, p6);
            Arc arc2 = fun.DrawArc(p3, p14, p2);
            Arc arc3 = fun.DrawArc(p5, p15, p4);
            Arc arc4 = fun.DrawArc(p144, p02, p133);
            Arc arc5 = fun.DrawArc(p155, p02, p144);
            Arc arc6 = fun.DrawArc(p133, p02, p155);
            Vector2 p7 = fun.getPointofcir(p13, p1, p6, p02, p144, p133);
            Vector2 p8 = new Vector2(-p7.X, p7.Y);
            Vector2 p9 = fun.getPointofcir(p14, p3, p2, p02, p155, p144);
            Vector2 p10 = fun.getPointofcir(p02, p155, p144, p15, p5, p4);
            Vector2 p11 = new Vector2(-p10.X, p10.Y);
            Vector2 p12 = new Vector2(-p9.X, p9.Y);
            Vector2 p16 = fun.Polar(p02, pi / 6, bd * 0.9 / 2);
            Vector2 p17 = fun.Polar(p02, 1.5 * pi, bd * 0.9 / 2);
            Vector2 p18 = fun.Polar(p02, pi / 3 + pi * 0.5, bd * 0.9 / 2);
            Arc arc7 = fun.DrawArc(p00, p02, p01);
            Vector2 p19 = fun.getPointForArcandLine(p18, fun.Polar(p18, pi / 6 + pi / 2, 100), p02, arc7);
            Vector2 p23 = fun.getPointForArcandLine(p17, fun.Polar(p17, 1.5 * pi - pi / 6, 100), p02, arc7);
            Vector2 p24 = fun.getPointForArcandLine(p18, fun.Polar(p18, pi, 100), p02, arc7);
            Vector2 p20 = new Vector2(-p19.X, p19.Y);
            Vector2 p21 = new Vector2(-p24.X, p24.Y);
            Vector2 p22 = new Vector2(-p23.X, p23.Y);

            Vector2 p25 = new Vector2(p02.X - bd*2, p01.Y);
            Vector2 p26 = new Vector2(p25.X, p00.Y);
            Vector2 p27 = new Vector2(p26.X - oal, p26.Y);
            Vector2 p28 = new Vector2(p27.X, p25.Y);
            //坐标点
            Vector2 p29 = new Vector2(p25.X, p25.Y / 2.0);
            Vector2 p30 = new Vector2(p27.X, p28.Y / 2.0);
            //下面的坐标点
            Vector2 p31 = fun.Polar(p02, pi / -2, offset * 5);
            // Vector2 p32 = fun.Polar(p27, pi / -2, offset * 1.5);
            Vector2 p32 = new Vector2(p27.X, p31.Y);
            Vector2 p33;
            Vector2 p34;
            Vector2 p35;
            Vector2 p36;
            Vector2 p37;
            Vector2 p38;
            Vector2 p39;
            Vector2 p40;
            Vector2 p41;
            Vector2 p42;
            Vector2 p43;

            fun.Axis(dxf, p31, 180, -90, "Y", "X", "Z", 0.5, 1.2, 1);
            fun.Axis(dxf, p32, 180, -90, "Z", "X", "Y", 0.5, 1.2, 0);
            fun.Axis(dxf, p02, 180, -90, "", "", "", 0.5, 1.2, 1);
            fun.Axis(dxf, p29, 180, -90, "", "", "", 0.5, 1.2, 0);
            fun.Axis(dxf, p30, 180, -90, "", "", "", 0.5, 1.2, 0);
            Circle circle1 = new Circle(fun.Polar(p02, 0, td / 2), 1.7 / 2);

            p33 = fun.Polar(p30, pi + pi / 4, 2 * 0.5);
            p34 = fun.Polar(p30, pi + pi / 6, 2 * 0.5 * 8);
            p35 = fun.Polar(p29, pi / 4, 2 * 0.5);
            p36 = fun.Polar(p29, pi / 4, 2 * 0.5 * 4);
            p37 = fun.Polar(fun.Polar(p02, 0, tdz / 2), pi / -6, 2);
            p38 = fun.Polar(p37, pi / -6, bd / 2.0);
            p39 = fun.Polar(p38, pi / -6, 0.2);
            p40 = fun.Polar(p02, pi - pi / 4, offset * 4.5);
            p41 = fun.Polar(p31, 0, bd / 2.0 + oal + 0.1);
            p42 = fun.Polar(p31, 0, bd / 2.0 + 0.1);
            p43 = fun.Polar(p31, 0, bd / 2.0);
            Line line1 = new Line(p33, p34);
            Line line2 = new Line(p35, p36);
            Line line3 = new Line(p02, fun.Polar(p02, pi - pi / 4, offset * 4.5));
            Line line4 = new Line(p37, p38);
            Vector2 v1 = fun.Polar(p34, pi + pi / 4, 2);
            Text tet1 = new Text("MCS,PCS", new Vector2 (v1.X -25,v1.Y ), 1.2, 0);
            Text tet2 = new Text("CIP,CRP", fun.Polar(p36, pi / 4, 2), 1.2, 0);
            Text tet3 = new Text("MCS,PCS,CIP", p40, 1.2, 0);
            Text tet4 = new Text("CRP", p39, 1.2, 0);
            Text tet5 = new Text("ISYC=301-05", fun.Polar(p40, pi / 2, 4), 1.2, 0);
            fun.Singlelinearrow(dxf, "TDZ", fun.Polar(p02, 20 * pi / 180, td / 2.0), 20, fun.Polar(p02, 20 * pi / 180, td / 2 + bd / 2), fun.Polar(p02, 20 * pi / 180, td / 2 + bd / 2 + 0.1), 1.2, 1.6);
            fun.Singlelinearrow(dxf, "FDP", p41, 0, p42, p43, 1.2, 1.6);
            dxf.AddEntity(new EntityObject[] { line1, line2, line3, line4, tet1, tet2, tet3, tet4, circle1 });

            /*
           Arc arc10= fun.DrawArc(p6, p02, p5);
            arc10.Linetype = Linetype.ByLayer;
            dxf.AddEntity(arc10);*/

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes[0].Bulge = Math.Tan((2 * pi / 3 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes[1].Bulge = Math.Tan((pi * 2 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 4);
            //Console.WriteLine(Math.Acos((ddchc / 2 - tdn / 2) / (ddch / 2)) * 180 / pi);
            //Console.ReadKey();
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes[2].Bulge = Math.Tan((2 * pi / 3 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes[3].Bulge = Math.Tan((pi * 2 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes[4].Bulge = Math.Tan((2 * pi / 3 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes[5].Bulge = Math.Tan((pi * 2 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p7));
            poly2.Vertexes[0].Bulge = Math.Tan(-(2 * pi / 3 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 5);
            poly2.Vertexes.Add(new LwPolylineVertex(p8));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p9));
            poly3.Vertexes[0].Bulge = Math.Tan(-(2 * pi / 3 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 5);
            poly3.Vertexes.Add(new LwPolylineVertex(p10));
            fun.PolyFill(dxf, poly3, 0.3, contour);

            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(p11));
            poly4.Vertexes[0].Bulge = Math.Tan(-(2 * pi / 3 - Math.Acos((ddchc * ddchc + ddch * ddch - tdn * tdn) / (2.0 * ddchc * ddch)) * 2) / 5);
            poly4.Vertexes.Add(new LwPolylineVertex(p12));
            fun.PolyFill(dxf, poly4, 0.3, contour);

            fun.drawcircle(dxf, p02, 0.9 * bd / 2, 0.3, contour);
            fun.drawcircle(dxf, p02, bd / 2, 0.3, contour);

            LwPolyline poly5 = new LwPolyline();
            poly5.Vertexes.Add(new LwPolylineVertex(p15));
            poly5.Vertexes[0].Bulge = Math.Tan(-pi / 3);
            poly5.Vertexes.Add(new LwPolylineVertex(p14));
            fun.PolyFillandlinetype(dxf, poly5, 0.1, refin, Linetype.Dashed);

            LwPolyline poly6 = new LwPolyline();
            poly6.Vertexes.Add(new LwPolylineVertex(p15));
            poly6.Vertexes[0].Bulge = Math.Tan(pi / 6);
            poly6.Vertexes.Add(new LwPolylineVertex(p14));
            fun.PolyFillandlinetype(dxf, poly6, 0.1, refin, Linetype.Dashed);

            LwPolyline poly7 = new LwPolyline();
            poly7.Vertexes.Add(new LwPolylineVertex(p25));
            poly7.Vertexes.Add(new LwPolylineVertex(p26));
            poly7.Vertexes.Add(new LwPolylineVertex(p27));
            poly7.Vertexes.Add(new LwPolylineVertex(p28));
            poly7.Vertexes.Add(new LwPolylineVertex(p25));
            fun.PolyFill(dxf, poly7, 0.3, contour);
            /*
            Vector2[] xuline1 = { p18, p19 };
            fun.drawPlinetype(dxf, xuline1, 0.15, refin, Linetype.Dashed);
            Vector2[] xuline2 = { p24, p18 };
            fun.drawPlinetype(dxf, xuline2, 0.15, refin, Linetype.Dashed);
            
            Vector2[] xuline3 = { p17, p22 };
            fun.drawPlinetype(dxf, xuline3, 0.15, refin, Linetype.Dashed);
            
            Vector2[] xuline4 = { p17, p23 };
            fun.drawPlinetype(dxf, xuline4, 0.15, refin, Linetype.Dashed);
            Vector2[] xuline5 = { p20, p16 };
            fun.drawPlinetype(dxf, xuline5, 0.15, refin, Linetype.Dashed);
            Vector2[] xuline6 = { p21, p16 };
            fun.drawPlinetype(dxf, xuline6, 0.15, refin, Linetype.Dashed);
            */

            Vector2[] cenline1 = { fun.Polar(p01, pi * 0.5, 4), fun.Polar(p00, 1.5 * pi, 4) };
            fun.drawPlinetype(dxf, cenline1, 0.15, center, Linetype.Center);
            Vector2[] cenline2 = { p02, fun.Polar(p02, pi + pi / 6, 0.4 * bd) };

            fun.drawPlinetype(dxf, cenline2, 0.15, center, Linetype.Center);
            Vector2[] cenline3 = { p02, fun.Polar(p02, 1.5 * pi + pi / 3, 0.4 * bd) };
            fun.drawPlinetype(dxf, cenline3, 0.15, center, Linetype.Center);
            /*
            Vector2[] cenline4 = { p18, fun.Polar(p18, 0.5 * pi + pi / 3, 0.1 * bd) };
            fun.drawPlinetype(dxf, cenline4, 0.15, centre, Linetype.Center);
            Vector2[] cenline5 = { p16, fun.Polar(p16, pi / 6, 0.1 * bd) };
            fun.drawPlinetype(dxf, cenline5, 0.15, centre, Linetype.Center);
            */


            LinearDimension linedim1 = new LinearDimension(new Line(p27, p26), offset * 1, 180, dimensionStyle);
            linedim1.UserText = "OAL ,LF,LPR,LTA ";
            dxf.AddEntity(linedim1);
            LinearDimension linedim2 = new LinearDimension(new Line(fun.Polar(p02, pi, bd / 2), fun.Polar(p02, 0, bd / 2)), offset * 4, 180, dimensionStyle);
            linedim2.UserText = "BD";
            dxf.AddEntity(linedim2);
            LinearDimension linedim7 = new LinearDimension(new Line(fun.Polar(p02, 0.5 * pi, td / 2), fun.Polar(p02, 1.5 * pi, td / 2)), offset * 6, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim7, "TD");


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void _ThreadCuttingDieRoundShape(Dictionary<string, Object> data)  //圆板牙
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层

            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            /*
            double d = 8;
            double p = 1.25;
            double b = 5;
            double D = 25;
            double DD1= D - (b/2+(6*System.Math.Sqrt(2)*Math.Tan (6*pi /180)));
            double D1 = D - ((b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180)))*2);
            double E = 9;
            double E1 = 1 ;
           
            double c = 0.8;
            double a = 0.5;
           // Vector2 pzk = new Vector2(0, 0);
           // Vector2 pzk1 = fun.Polar(pzk,pi/2,(d/2)-p);
            double d1 = 0.1+(D1 /2)-(d/2-p );//排泄孔
            double ajj = 20;
            double dj =1;
            double l = 2;
            double drjj =1;
            double sh = 0;
            */

            double d = Convert.ToDouble(data["TD"]);
            double p = Convert.ToDouble(data["TP"]);
            double b = Convert.ToDouble(data["TDZ"]);
            double D = Convert.ToDouble(data["BD"]);
            double DD1 = D - (b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180)));
            double D1 = Convert.ToDouble(data["d1"]);
            double E = Convert.ToDouble(data["OAL"]);
            // double E1 = E * 3/5;
            double E1 = Convert.ToDouble(data["E1"]);
            double c = Convert.ToDouble(data["KJ1"]);
            double a = Convert.ToDouble(data["A"]);
            double ajj = Convert.ToDouble(data["AJJ"]);
            double dj = Convert.ToDouble(data["DJ"]);
            double l = Convert.ToDouble(data["L"]);
            double drjj = Convert.ToDouble(data["DRJJ"]);
            double sh = Convert.ToDouble(data["SH"]);
            double d1 = 0.1 + (D1 / 2) - (d / 2 - p);//排泄孔



            /*
            double d = 1;
            double p = 0.25;
            double D = 16;
            double D1 = 11;
            double E = 5;
            double E1 = 2;
            double c = 0.5;
            double b = 3;
            double a = 0.2;
     
            double d1 = 0.01+(D1 /2)-(d/2-p );
            double DD1 = D - (b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180)));
              */
            double yx = (d / 2 - p);
            double yx2 = d / 2;
            double zxj = (D1 / 2) - (d1 / 2);
            double jd1 = (d1 / 2);
            double kc = 85 * pi / 180;


            if (D > 16)
            {
                D1 = D - ((b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180))) * 2);
            }

            //double E1 = (8 / 9 * E);




            if (D < 25)
            {



                //中心三角带
                Vector2 p0 = new Vector2(0, 0);
                Vector2 p1 = new Vector2(0, D1 / 2);
                Vector2 p2 = fun.Polar(p0, 210 * pi / 180, D1 / 2);
                Vector2 p2y = fun.Polar(p0, 210 * pi / 180, D1 / 2 - d1 / 2); //-135度排泄孔圆心

                Vector2 p3 = fun.Polar(p0, -30 * pi / 180, D / 2 - a);
                Vector2 p3y = fun.Polar(p0, -30 * pi / 180, D1 / 2 - d1 / 2);// -45度排泄孔圆心

                //中心螺纹孔/排泄孔
                Vector2 p4 = fun.Polar(p0, pi / 2, D1 / 2);
                Vector2 p1y = fun.Polar(p4, pi / -2, d1 / 2);//90度排泄孔圆心
                Vector2 p5 = fun.Polar(p0, pi * 0.5 + Math.Acos((yx * yx + zxj * zxj - jd1 * jd1) / (2 * yx * zxj)), yx);

                Vector2 p6 = fun.Polar(p0, pi / 2 + Math.Acos((yx2 * yx2 + zxj * zxj - jd1 * jd1) / (2 * yx2 * zxj)), yx2);
                Vector2 p7 = fun.mirrorpoint(p5, p0, p4);
                Vector2 p8 = fun.mirrorpoint(p6, p0, p4);

                var p9 = fun.PointRotate(p0, p5, 120 * pi / 180);
                var p10 = fun.PointRotate(p0, p5, 240 * pi / 180);
                var p11 = fun.PointRotate(p0, p6, 120 * pi / 180);
                var p12 = fun.PointRotate(p0, p6, 240 * pi / 180);
                var p13 = fun.PointRotate(p0, p7, 120 * pi / 180);
                var p14 = fun.PointRotate(p0, p7, 240 * pi / 180);
                var p15 = fun.PointRotate(p0, p8, 120 * pi / 180);
                var p16 = fun.PointRotate(p0, p8, 240 * pi / 180);
                //头顶卡槽
                Vector2 p17 = fun.Polar(p0, kc, D / 2);
                Vector2 p18 = fun.Polar(p0, pi / 2, D);
                Vector2 p19 = fun.mirrorpoint(p17, p0, p18);
                Vector2 p20 = fun.Polar(p17, kc - pi, D / 2 - D1 / 2);
                Vector2 p21 = fun.mirrorpoint(p20, p0, p18);

                //中心线
                Vector2 zxx1 = fun.Polar(p18, pi / -2, D * 2);
                Vector2 zxx2 = fun.Polar(p0, pi, D);
                Vector2 zxx3 = fun.Polar(zxx2, 0, D * 2);



                //两个耳朵

                Vector2 p22 = fun.Polar(p0, 135 * pi / 180, D1 / 2);
                Vector2 p23 = fun.Polar(p22, pi / -2, System.Math.Sqrt(2) * c);
                Vector2 p24 = fun.Polar(p0, (45 - 16) * pi / 180 + pi / 2, D / 2);
                Vector2 p25 = fun.Polar(p0, 157 * pi / 180, D / 2);
                Vector2 p26 = fun.mirrorpoint(p23, p0, p18);
                Vector2 p27 = fun.mirrorpoint(p24, p0, p18);
                Vector2 p28 = fun.mirrorpoint(p25, p0, p18);


                //下面那个槽
                Vector2 p29 = fun.Polar(p0, 11 * pi / 180 - pi / 2, D / 2);
                Vector2 p30 = fun.Polar(p29, 135 * pi / 180, System.Math.Sqrt(Math.Pow(b, 2) / 2));
                Vector2 p31 = fun.mirrorpoint(p29, p0, p18);






                //刨视图
                Vector2 p32 = fun.Polar(p0, pi / -2, D / 2);
                Vector2 p33 = fun.Polar(p32, 0, D * 1.5);
                Vector2 p333 = fun.Polar(p33, pi / 2, a);
                //刨视图中心线
                Vector2 ppzy = new Vector2(p33.X + E / 2, p33.Y - E / 2);
                Vector2 ppzy1 = fun.Polar(ppzy, pi / 2, D + E);
                Vector2 p34 = fun.Polar(p33, pi / 2, D / 2 - a - D1 / 2);
                Vector2 p35 = new Vector2(p34.X, p34.Y + D1 / 4);
                Vector2 p36 = fun.Polar(p35, pi / 2, p);
                Vector2 p3z = fun.Polar(p35, pi / 2, D1 / 4);//中心线
                Vector2 pzxx = fun.Polar(p3z, pi, E / 2);
                Vector2 pzxx1 = fun.Polar(pzxx, 0, E * 2);
                Vector2 p37 = fun.Polar(p3z, pi / 2, D1 / 4);
                Vector2 p38 = fun.Polar(p37, pi / 2, p);
                Vector2 p39 = fun.Polar(p37, pi / 2, D1 / 4);
                Vector2 p42 = new Vector2(p33.X, D / 2);
                Vector2 p43p = fun.mirrorpoint(p42, ppzy, ppzy1);
                Vector2 p43 = fun.Polar(p43p, pi, a);
                Vector2 p444 = new Vector2(p43.X + a, p43.Y - a);
                Vector2 p44 = fun.mirrorpoint(p39, ppzy, ppzy1);
                Vector2 p45 = fun.mirrorpoint(p34, ppzy, ppzy1);
                Vector2 p334 = fun.mirrorpoint(p333, ppzy, ppzy1);
                Vector2 p46 = new Vector2(p334.X - a, p334.Y - a);
                Vector2 p47 = fun.Polar(p33, 0, a);



                /*
                Vector2 p43 = fun.Polar(p42,0,E-a);
                Vector2 p444 = new Vector2(p43.X + a, p43.Y - a);
                
                Vector2 p44  = fun.mirrorpoint(p39, ppzy, ppzy1);
                Vector2 p45 = fun.Polar(p44,pi/-2,D1 );
                Vector2 p334=fun.mirrorpoint(p34, ppzy, ppzy1);
                Vector2 p46 = new Vector2(p334.X -a,p334.Y -a);
                Vector2 p47 = new Vector2(p33.X +a,p33.Y );

                */



                //右边深度
                Vector2 p48 = fun.Polar(p39, 0, E1);
                Vector2 p49 = fun.Polar(p38, 0, E1);
                Vector2 p50 = fun.Polar(p37, 0, E1);
                Vector2 p51 = fun.Polar(p36, 0, E1);
                Vector2 p52 = fun.Polar(p35, 0, E1);
                Vector2 p53 = fun.Polar(p34, 0, E1);


                //中间的间隔
                Vector2 p54 = fun.Polar(p35, 45 * pi / 180, (System.Math.Sqrt(2)) * (E1 / 3));
                Vector2 p55 = fun.Polar(p54, 0, E1 / 3);
                Vector2 p56 = fun.Polar(p54, pi / 2, p);
                Vector2 p57 = fun.Polar(p56, 0, E1 / 3);
                Vector2 p58 = fun.Polar(p37, -45 * pi / 180, (System.Math.Sqrt(2)) * (E1 / 3));
                Vector2 p59 = fun.Polar(p58, 0, E1 / 3);
                Vector2 p60 = fun.Polar(p58, pi / 2, p);
                Vector2 p61 = fun.Polar(p60, 0, E1 / 3);


                //中间凹槽
                Vector2 p62 = fun.Polar(p33, 0, E / 2);
                Vector2 p63 = fun.Polar(p62, 0, b / 2);
                Vector2 p64 = fun.Polar(p62, pi, b / 2);
                Vector2 p65 = fun.Polar(p63, 135 * pi / 180, b / System.Math.Sqrt(2));



                Circle circle2 = new Circle(new Vector3(0, 0, 0), D1 / 2);//圆
                circle2.Lineweight = netDxf.Lineweight.W15;//W线宽;
                dxf.AddEntity(circle2);

                Vector2 p105 = fun.Polar(p0, pi, D1 / 2);
                Vector2 p205 = fun.Polar(p0, 0, D1 / 2);


                LwPolyline poly201 = new LwPolyline();
                poly201.Vertexes.Add(new LwPolylineVertex(p105));
                poly201.Vertexes[0].Bulge = Math.Tan(pi / 4);
                poly201.Vertexes.Add(new LwPolylineVertex(p205));
                poly201.Vertexes[1].Bulge = Math.Tan(pi / 4);
                poly201.Vertexes.Add(new LwPolylineVertex(p105));
                fun.PolyFill(dxf, poly201, 0.15, contour);


                /*
                //连线上卡槽
                Line line1 = new Line(p17, p20);
                Line line2 = new Line(p19, p21);
                line1.Lineweight = netDxf.Lineweight.W40;
                line2.Lineweight = netDxf.Lineweight.W40;
                fun.PolyFill(dxf, line1, 0.4, contour);
                */
                double hb = p17.X - p19.X;
                double xxb = d1 / 2;

                LwPolyline poly100 = new LwPolyline();
                poly100.Vertexes.Add(new LwPolylineVertex(p17));
                poly100.Vertexes.Add(new LwPolylineVertex(p20));
                poly100.Vertexes[1].Bulge = Math.Tan((10 * pi / 180) / 4);
                poly100.Vertexes.Add(new LwPolylineVertex(p21));
                poly100.Vertexes.Add(new LwPolylineVertex(p19));
                fun.PolyFill(dxf, poly100, 0.15, contour);



                Line line001 = new Line(p24, p23);
                Line line002 = new Line(p23, p25);
                line001.Lineweight = Lineweight.W25;
                line001.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line001);
                line002.Lineweight = Lineweight.W25;
                line002.Linetype = Linetype.Dashed;
                dxf.AddEntity(line002);

                Line line003 = new Line(p27, p26);
                Line line004 = new Line(p26, p28);
                line003.Lineweight = Lineweight.W25;
                line003.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line003);
                line004.Lineweight = Lineweight.W25;
                line004.Linetype = Linetype.Dashed;
                dxf.AddEntity(line004);








                /*
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
              
                
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.Vertexes[2].Bulge = Math.Tan(((fun.CalAngle(p0, p24) - fun.CalAngle(p0, p25))) / 4);
                fun.PolyFill(dxf, poly1, 0.3, contour);


                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p27));
                poly2.Vertexes.Add(new LwPolylineVertex(p26));
                poly2.Vertexes.Add(new LwPolylineVertex(p28));
                poly2.Vertexes.Add(new LwPolylineVertex(p27));
                poly2.Vertexes[2].Bulge = Math.Tan(((fun.CalAngle(p0, p27) - fun.CalAngle(p0, p28))) / 4);
                fun.PolyFill(dxf, poly2, 0.3, contour);
                */
                Line line005 = new Line(p29, p30);
                Line line006 = new Line(p30, p31);
                line005.Lineweight = Lineweight.W25;
                line005.Linetype = Linetype.Dashed;
                dxf.AddEntity(line005);
                line006.Lineweight = Lineweight.W25;
                line006.Linetype = Linetype.Dashed;
                dxf.AddEntity(line006);

                /*
                LwPolyline poly3 = new LwPolyline();
                poly3.Vertexes.Add(new LwPolylineVertex(p29));
                poly3.Vertexes.Add(new LwPolylineVertex(p30));
                poly3.Vertexes.Add(new LwPolylineVertex(p31));
                poly3.Vertexes[2].Bulge = Math.Tan(((fun.CalAngle(p0, p29) - fun.CalAngle(p0, p31))) / 4);
                fun.PolyFill(dxf, poly3, 0.3, contour);
                */






                //中心线
                Line line9 = new Line(p18, zxx1);
                Line line10 = new Line(zxx2, zxx3);
                line9.Lineweight = Lineweight.W15;//Lineweight指线宽
                line9.Layer = centre;//Layer指图层
                line9.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line9); //提取
                line10.Lineweight = Lineweight.W15;//Lineweight指线宽
                line10.Layer = centre;//Layer指图层
                line10.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line10); //提取

                //刨视图中心线
                Line line11 = new Line(pzxx, pzxx1);
                line11.Lineweight = Lineweight.W15;
                line11.Linetype = Linetype.DashDot;
                line11.Layer = centre;
                dxf.AddEntity(line11);




                //刨视图连线
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p333));
                poly1.Vertexes.Add(new LwPolylineVertex(p34));
                poly1.Vertexes.Add(new LwPolylineVertex(p35));
                poly1.Vertexes.Add(new LwPolylineVertex(p36));
                poly1.Vertexes.Add(new LwPolylineVertex(p37));
                poly1.Vertexes.Add(new LwPolylineVertex(p38));
                poly1.Vertexes.Add(new LwPolylineVertex(p39));
                poly1.Vertexes.Add(new LwPolylineVertex(p42));
                poly1.Vertexes.Add(new LwPolylineVertex(p43));


                poly1.Vertexes[8].Bulge = Math.Tan((45 * pi / 180) / -4);

                poly1.Vertexes.Add(new LwPolylineVertex(p444));
                poly1.Vertexes.Add(new LwPolylineVertex(p44));
                poly1.Vertexes.Add(new LwPolylineVertex(p45));
                poly1.Vertexes.Add(new LwPolylineVertex(p334));

                poly1.Vertexes[12].Bulge = Math.Tan((45 * pi / 180) / -4);
                poly1.Vertexes.Add(new LwPolylineVertex(p46));
                poly1.Vertexes.Add(new LwPolylineVertex(p47));
                poly1.Vertexes[14].Bulge = Math.Tan((45 * pi / 180) / -4);
                poly1.Vertexes.Add(new LwPolylineVertex(p333));

                fun.PolyFill(dxf, poly1, 0.15, contour);

                //刨视图右边那个空框
                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p44));
                poly2.Vertexes.Add(new LwPolylineVertex(p48));
                poly2.Vertexes.Add(new LwPolylineVertex(p53));
                poly2.Vertexes.Add(new LwPolylineVertex(p45));
                poly2.Vertexes.Add(new LwPolylineVertex(p44));

                fun.PolyFill(dxf, poly2, 0.15, contour);


                //中间包括两杠的框
                LwPolyline poly3 = new LwPolyline();
                poly3.Vertexes.Add(new LwPolylineVertex(p34));
                poly3.Vertexes.Add(new LwPolylineVertex(p39));
                poly3.Vertexes.Add(new LwPolylineVertex(p48));
                poly3.Vertexes.Add(new LwPolylineVertex(p53));
                poly3.Vertexes.Add(new LwPolylineVertex(p34));

                fun.PolyFill(dxf, poly3, 0.15, contour);

                //中间的杠
                LwPolyline poly4 = new LwPolyline();
                poly4.Vertexes.Add(new LwPolylineVertex(p35));
                poly4.Vertexes.Add(new LwPolylineVertex(p36));
                poly4.Vertexes.Add(new LwPolylineVertex(p56));
                poly4.Vertexes.Add(new LwPolylineVertex(p54));
                poly4.Vertexes.Add(new LwPolylineVertex(p35));
                fun.PolyFill(dxf, poly4, 0.105, contour);

                LwPolyline poly5 = new LwPolyline();
                poly5.Vertexes.Add(new LwPolylineVertex(p56));
                poly5.Vertexes.Add(new LwPolylineVertex(p57));
                poly5.Vertexes.Add(new LwPolylineVertex(p55));
                poly5.Vertexes.Add(new LwPolylineVertex(p54));
                poly5.Vertexes.Add(new LwPolylineVertex(p56));
                fun.PolyFill(dxf, poly5, 0.105, contour);

                LwPolyline poly6 = new LwPolyline();
                poly6.Vertexes.Add(new LwPolylineVertex(p57));
                poly6.Vertexes.Add(new LwPolylineVertex(p51));
                poly6.Vertexes.Add(new LwPolylineVertex(p52));
                poly6.Vertexes.Add(new LwPolylineVertex(p55));
                poly6.Vertexes.Add(new LwPolylineVertex(p57));
                fun.PolyFill(dxf, poly6, 0.105, contour);


                LwPolyline poly7 = new LwPolyline();
                poly7.Vertexes.Add(new LwPolylineVertex(p37));
                poly7.Vertexes.Add(new LwPolylineVertex(p38));
                poly7.Vertexes.Add(new LwPolylineVertex(p60));
                poly7.Vertexes.Add(new LwPolylineVertex(p58));
                poly7.Vertexes.Add(new LwPolylineVertex(p37));
                fun.PolyFill(dxf, poly7, 0.105, contour);


                LwPolyline poly8 = new LwPolyline();
                poly8.Vertexes.Add(new LwPolylineVertex(p60));
                poly8.Vertexes.Add(new LwPolylineVertex(p61));
                poly8.Vertexes.Add(new LwPolylineVertex(p59));
                poly8.Vertexes.Add(new LwPolylineVertex(p58));
                poly8.Vertexes.Add(new LwPolylineVertex(p60));
                fun.PolyFill(dxf, poly8, 0.105, contour);

                LwPolyline poly9 = new LwPolyline();
                poly9.Vertexes.Add(new LwPolylineVertex(p61));
                poly9.Vertexes.Add(new LwPolylineVertex(p49));
                poly9.Vertexes.Add(new LwPolylineVertex(p50));
                poly9.Vertexes.Add(new LwPolylineVertex(p59));
                fun.PolyFill(dxf, poly9, 0.105, contour);



                LwPolyline poly10 = new LwPolyline();
                poly10.Vertexes.Add(new LwPolylineVertex(p63));
                poly10.Vertexes.Add(new LwPolylineVertex(p65));
                poly10.Vertexes.Add(new LwPolylineVertex(p64));
                fun.PolyFill(dxf, poly10, 0.105, contour);

                LwPolyline poly11 = new LwPolyline();
                poly11.Vertexes.Add(new LwPolylineVertex(p333));
                poly11.Vertexes.Add(new LwPolylineVertex(p34));
                poly11.Vertexes.Add(new LwPolylineVertex(p45));
                poly11.Vertexes.Add(new LwPolylineVertex(p334));
                poly11.Vertexes.Add(new LwPolylineVertex(p46));
                poly11.Vertexes.Add(new LwPolylineVertex(p64));
                poly11.Vertexes.Add(new LwPolylineVertex(p65));
                poly11.Vertexes.Add(new LwPolylineVertex(p63));
                poly11.Vertexes.Add(new LwPolylineVertex(p47));
                poly11.Vertexes.Add(new LwPolylineVertex(p333));

                //poly11.SetConstantWidth(0.05);
                poly11.IsClosed = true;
                fun.PolyFill(dxf, poly11, 0.105, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                String[] htype11 = new String[100];
                Line[] hline11 = new Line[100];
                Arc[] harc11 = new Arc[100];
                int hnumst11 = poly11.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst11; i++)
                {
                    htype11[i] = poly11.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype11[i] == "Line")
                    {
                        hline11[i] = (Line)poly11.Explode()[i];
                    }
                    if (htype11[i] == "Arc")
                    {
                        harc11[i] = (Arc)poly11.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype11, hnumst11, 45, 1, hline11, harc11, hatching);



                LwPolyline poly22 = new LwPolyline();
                poly22.Vertexes.Add(new LwPolylineVertex(p39));
                poly22.Vertexes.Add(new LwPolylineVertex(p42));
                poly22.Vertexes.Add(new LwPolylineVertex(p43));
                poly22.Vertexes.Add(new LwPolylineVertex(p444));
                poly22.Vertexes.Add(new LwPolylineVertex(p44));
                poly22.Vertexes.Add(new LwPolylineVertex(p39));


                //poly22.SetConstantWidth(0.05);
                poly22.IsClosed = true;
                fun.PolyFill(dxf, poly22, 0.105, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                String[] htype22 = new String[100];
                Line[] hline22 = new Line[100];
                Arc[] harc22 = new Arc[100];
                int hnumst22 = poly22.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst22; i++)
                {
                    htype22[i] = poly22.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype22[i] == "Line")
                    {
                        hline22[i] = (Line)poly22.Explode()[i];
                    }
                    if (htype22[i] == "Arc")
                    {
                        harc22[i] = (Arc)poly22.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype22, hnumst22, 45, 1, hline22, harc22, hatching);





                //排泄孔
                Arc arc1 = fun.DrawArc(p7, p1y, p5);

                fun.drawBArc(dxf, arc1, 0.15, contour);
                Arc arc2 = fun.DrawArc(p13, p3y, p9);
                fun.drawBArc(dxf, arc2, 0.15, contour);

                Arc arc3 = fun.DrawArc(p14, p2y, p10);
                fun.drawBArc(dxf, arc3, 0.15, contour);

                //螺纹孔
                Arc arc4 = fun.DrawArc(p6, p0, p16);
                fun.drawBArc(dxf, arc4, 0.15, contour);

                Arc arc5 = fun.DrawArc(p5, p0, p14);
                fun.drawBArc(dxf, arc5, 0.15, contour);

                Arc arc6 = fun.DrawArc(p10, p0, p13);
                fun.drawBArc(dxf, arc6, 0.15, contour);

                Arc arc7 = fun.DrawArc(p12, p0, p15);
                fun.drawBArc(dxf, arc7, 0.15, contour);

                Arc arc8 = fun.DrawArc(p9, p0, p7);
                fun.drawBArc(dxf, arc8, 0.15, contour);

                Arc arc9 = fun.DrawArc(p11, p0, p8);
                fun.drawBArc(dxf, arc9, 0.15, contour);

                Arc arc10 = fun.DrawArc(p19, p0, p17);
                fun.drawBArc(dxf, arc10, 0.15, contour);



                //标注
                Vector2 p0000 = fun.Polar(p0, pi / 2, D);
                Vector2 p1000 = fun.Polar(p0, 45 * pi / 180, D);
                Vector2 p1001 = fun.Polar(p0, 135 * pi / 180, D);
                Vector2 p1002 = fun.Polar(p1000, -45 * pi / 180, c);
                Vector2 p1003 = fun.Polar(p1001, -135 * pi / 180, c);



                //刨视图

                Line line1000 = new Line(p0, p1000);
                Line line1001 = new Line(p0, p1001);
                Line line1002 = new Line(p0, p0000);
                Line line1003 = new Line(p1001, p0);
                Line line1004 = new Line(p1002, p26);
                Line line1005 = new Line(p1003, p23);
                dxf.AddEntity(line1000);
                dxf.AddEntity(line1001);
                dxf.AddEntity(line1002);
                dxf.AddEntity(line1003);
                dxf.AddEntity(line1004);
                dxf.AddEntity(line1005);


                fun.jdbz2(dxf, line1000, line1002, 15, 2.5, 2, 2.5, "45", "", "");
                fun.jdbz2(dxf, line1002, line1001, 15, 2.5, 2, 2.5, "45", "", "");
                fun.dimrot1(dxf, p1000, p1002, -45, 5, 5, 2.5, 2, 0.9, "c=" + c, "", "");
                fun.dimrot1(dxf, p1001, p1003, 45, 5, 5, 2.5, 2, 0.9, "c=" + c, "", "");

                fun.dimrot1(dxf, p42, p48, 0, D, 5, 2.5, 2, 0.9, "E1=" + E1, "", "");
                fun.dimrot1(dxf, p42, p44, 0, D + D / 2, 5, 2.5, 2, 0.9, "E=" + E, "", "");
                fun.dimrot1(dxf, p42, p33, -90, D + D / 2, 5, 2.5, 2, 0.9, "D=" + D, "", "");
                fun.dimrot1(dxf, p48, p53, -90, D, 5, 2.5, 2, 0.9, "D1=" + D1, "", "");
                fun.dimrot1(dxf, p33, p47, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p33, fun.Polar(p33, 0, E / 2), 180, D + D / 2, 5, 2.5, 2, 0.9, "0.5E", "", "");
                fun.dimrot1(dxf, p46, p334, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p63, p64, 180, D / 2, 5, 2.5, 2, 0.9, "b" + b, "", "");

            }
            else
            {
                if (E1 == 0)
                {
                    E1 = E;
                }
                else if (E1 == 1)
                {
                    E1 = 8.0 / 9 * E;
                }
                Vector2 p0 = new Vector2(0, 0);
                Vector2 p1 = fun.Polar(p0, pi / 2, D1 / 2);
                Vector2 p1p = fun.Polar(p1, pi / -2, d1 / 2);
                Vector2 p2 = fun.Polar(p0, pi / 2 + 72 * pi / 180, D1 / 2);
                Vector2 p2p = fun.Polar(p2, -18 * pi / 180, d1 / 2);
                Vector2 p3 = fun.Polar(p0, 234 * pi / 180, D1 / 2);
                Vector2 p3p = fun.Polar(p3, 54 * pi / 180, d1 / 2);
                Vector2 p4 = fun.Polar(p0, 306 * pi / 180, D1 / 2);
                Vector2 p4p = fun.Polar(p4, 126 * pi / 180, d1 / 2);
                Vector2 p5 = fun.Polar(p0, 18 * pi / 180, D1 / 2);
                Vector2 p5p = fun.Polar(p5, -162 * pi / 180, d1 / 2);
                Vector2 p6 = fun.Polar(p0, pi * 0.5 + Math.Acos((yx * yx + zxj * zxj - jd1 * jd1) / (2 * yx * zxj)), yx);

                Vector2 p7 = fun.Polar(p0, pi / 2 + Math.Acos((yx2 * yx2 + zxj * zxj - jd1 * jd1) / (2 * yx2 * zxj)), yx2);
                Vector2 pz = fun.Polar(p0, pi / 2, D);
                Vector2 pz1 = fun.Polar(p0, pi / -2, D);
                Vector2 p8 = fun.mirrorpoint(p6, pz, pz1);
                Vector2 p9 = fun.mirrorpoint(p7, pz, pz1);

                //头顶卡槽
                Vector2 p26 = fun.Polar(p0, kc, D / 2);
                Vector2 p28 = fun.mirrorpoint(p26, pz, pz1);

                Vector2 p29 = fun.Polar(p26, kc - pi, D / 2 - D1 / 2);
                Vector2 p30 = fun.mirrorpoint(p29, pz, pz1);





                //正方形四点
                Vector2 p31 = fun.Polar(p0, 45 * pi / 180, D1 / 2);
                Vector2 p32 = fun.Polar(p0, 135 * pi / 180, D1 / 2);
                Vector2 p33 = fun.Polar(p0, -135 * pi / 180, D1 / 2);
                Vector2 p34 = fun.Polar(p0, -45 * pi / 180, D1 / 2);


                //中心线
                Vector2 pzx = fun.Polar(p0, 45 * pi / 180, D);
                Vector2 pzx1 = fun.Polar(p0, 135 * pi / 180, D);
                Vector2 pzx2 = fun.Polar(p0, -135 * pi / 180, D);
                Vector2 pzx3 = fun.Polar(p0, -45 * pi / 180, D);

                Vector2 pyz = fun.Polar(p0, 0, D);
                Vector2 pyz2 = fun.Polar(p0, pi, D);
                Vector2 pyz3 = fun.Polar(p0, pi / 2, D);
                Vector2 pyz4 = fun.Polar(p0, pi / -2, D);


                //四个槽孔


                Vector2 p35 = fun.Polar(p31, -45 * pi / 180, c);
                Vector2 p36 = fun.Polar(p0, 56 * pi / 180, D / 2);
                Vector2 p37 = fun.Polar(p0, 28 * pi / 180, D / 2);

                Vector2 p38 = fun.Polar(p32, -135 * pi / 180, c);
                Vector2 p39 = fun.Polar(p0, 124 * pi / 180, D / 2);
                Vector2 p40 = fun.Polar(p0, 152 * pi / 180, D / 2);

                Vector2 p41 = fun.Polar(p0, -121 * pi / 180, D / 2);
                Vector2 p42 = fun.Polar(p0, -149 * pi / 180, D / 2);

                Vector2 p43 = fun.Polar(p34, 0, ((D / 2 - D1 / 2) / (Math.Cos(45 * pi / 180))));
                Vector2 p44 = fun.Polar(p34, -90 * pi / 180, ((D / 2 - D1 / 2) / (Math.Cos(45 * pi / 180))));

                Vector2 p45 = fun.Polar(p26, kc - pi, D / 2 - DD1 / 2);
                Vector2 p46 = fun.mirrorpoint(p45, pz, pz1);


                //刨切线
                Vector2 p91 = fun.Polar(p0, pi / 2 + (ajj * pi / 180), D + 5);
                Vector2 p92 = fun.Polar(p91, (pi / 2 + (ajj * pi / 180)) - (90 * pi / 180), 5);
                Vector2 p93 = fun.Polar(p0, pi / -4, D + 5);
                Vector2 p94 = fun.Polar(p93, pi / 4, 5);
                Vector2 p95 = fun.Polar(p92, (pi / 2 + (ajj * pi / 180)), 0.71 / 2);
                Vector2 p96 = fun.Polar(p92, (pi / 2 + (ajj * pi / 180)) - pi, 0.71 / 2);
                Vector2 p97 = fun.Polar(p92, (pi / 2 + (ajj * pi / 180)) - (90 * pi / 180), 2.0);
                Vector2 p98 = fun.Polar(p94, pi / 2 + pi / 4, 0.71 / 2);
                Vector2 p99 = fun.Polar(p94, pi / -4, 0.71 / 2);
                Vector2 p105 = fun.Polar(p94, pi / 4, 2.0);
                Vector2 p108 = fun.Polar(p92, pi, 2);
                Vector2 p107 = fun.Polar(p94, pi / -4, 2);





                Line line105 = new Line(p0, p91);
                line105.Lineweight = Lineweight.W25;
                line105.Linetype = Linetype.DashDot;
                dxf.AddEntity(line105);
                Line line106 = new Line(p91, p92);
                line106.Lineweight = Lineweight.W25;

                dxf.AddEntity(line106);
                Line line107 = new Line(p0, p93);
                line107.Lineweight = Lineweight.W25;
                line107.Linetype = Linetype.DashDot;
                dxf.AddEntity(line107);
                Line line108 = new Line(p93, p94);
                line108.Lineweight = Lineweight.W25;

                dxf.AddEntity(line108);
                Solid entity = new Solid(p95, p96, p97);
                dxf.AddEntity(entity);

                Solid entity1 = new Solid(p98, p99, p105);
                dxf.AddEntity(entity1);

                Text txt = new Text("A", p108, 2.5, 2);
                Text txt1 = new Text("A", p107, 2.5, 2);
                dxf.AddEntity(txt);
                dxf.AddEntity(txt1);

                var p10 = fun.PointRotate(p0, p6, 72 * pi / 180);
                var p11 = fun.PointRotate(p0, p6, 144 * pi / 180);
                var p12 = fun.PointRotate(p0, p6, 216 * pi / 180);
                var p13 = fun.PointRotate(p0, p6, 288 * pi / 180);
                var p14 = fun.PointRotate(p0, p7, 72 * pi / 180);
                var p15 = fun.PointRotate(p0, p7, 144 * pi / 180);
                var p16 = fun.PointRotate(p0, p7, 216 * pi / 180);
                var p17 = fun.PointRotate(p0, p7, 288 * pi / 180);
                var p18 = fun.PointRotate(p0, p8, 72 * pi / 180);
                var p19 = fun.PointRotate(p0, p8, 144 * pi / 180);
                var p20 = fun.PointRotate(p0, p8, 216 * pi / 180);
                var p21 = fun.PointRotate(p0, p8, 288 * pi / 180);
                var p22 = fun.PointRotate(p0, p9, 72 * pi / 180);
                var p23 = fun.PointRotate(p0, p9, 144 * pi / 180);
                var p24 = fun.PointRotate(p0, p9, 216 * pi / 180);
                var p25 = fun.PointRotate(p0, p9, 288 * pi / 180);

                /*
                //头顶卡槽连线
                Line line1 = new Line(p26,p29);
                line1.Lineweight = Lineweight.W50;
                line1.Layer = contour ;
                dxf.AddEntity(line1);
                



                Line line2 = new Line(p28, p30);
                line2.Lineweight = Lineweight.W50;
                line2.Layer = contour;
                dxf.AddEntity(line2);
                */

                double hb1 = p26.X - p28.X;
                double xxb1 = d1 / 2;

                LwPolyline poly100 = new LwPolyline();
                poly100.Vertexes.Add(new LwPolylineVertex(p26));
                poly100.Vertexes.Add(new LwPolylineVertex(p29));
                poly100.Vertexes[1].Bulge = Math.Tan((10 * pi / 180) / 4);
                poly100.Vertexes.Add(new LwPolylineVertex(p30));
                poly100.Vertexes.Add(new LwPolylineVertex(p28));
                fun.PolyFill(dxf, poly100, 0.4, contour);




                //最小圆的正方形虚线
                Line line3 = new Line(p31, p32);
                line3.Linetype = Linetype.Dashed;
                line3.Layer = refin;
                line3.Lineweight = Lineweight.W25;
                dxf.AddEntity(line3);
                Line line4 = new Line(p32, p33);
                line4.Linetype = Linetype.Dashed;
                line4.Layer = refin;
                line4.Lineweight = Lineweight.W25;
                dxf.AddEntity(line4);

                Line line5 = new Line(p33, p34);
                line5.Linetype = Linetype.Dashed;
                line5.Layer = refin;
                line5.Lineweight = Lineweight.W25;
                dxf.AddEntity(line5);
                Line line6 = new Line(p34, p31);
                line6.Linetype = Linetype.Dashed;
                line6.Layer = refin;
                line6.Lineweight = Lineweight.W25;
                dxf.AddEntity(line6);
                //四个槽孔
                Line line7 = new Line(p35, p36);
                line7.Linetype = Linetype.Dashed;
                line7.Layer = refin;
                line7.Lineweight = Lineweight.W35;
                dxf.AddEntity(line7);

                Line line8 = new Line(p35, p37);
                line8.Linetype = Linetype.Dashed;
                line8.Layer = refin;
                line8.Lineweight = Lineweight.W35;
                dxf.AddEntity(line8);
                Line line9 = new Line(p38, p39);
                line9.Linetype = Linetype.Dashed;
                line9.Layer = refin;
                line9.Lineweight = Lineweight.W35;
                dxf.AddEntity(line9);
                Line line10 = new Line(p38, p40);
                line10.Linetype = Linetype.Dashed;
                line10.Layer = refin;
                line10.Lineweight = Lineweight.W35;
                dxf.AddEntity(line10);
                Line line11 = new Line(p33, p41);
                line11.Linetype = Linetype.Dashed;
                line11.Layer = refin;
                line11.Lineweight = Lineweight.W35;
                dxf.AddEntity(line11);
                Line line12 = new Line(p33, p42);
                line12.Linetype = Linetype.Dashed;
                line12.Layer = refin;
                line12.Lineweight = Lineweight.W35;
                dxf.AddEntity(line12);
                Line line13 = new Line(p34, p43);
                line13.Linetype = Linetype.Dashed;
                line13.Layer = refin;
                line13.Lineweight = Lineweight.W35;
                dxf.AddEntity(line13);
                Line line14 = new Line(p34, p44);
                line14.Linetype = Linetype.Dashed;
                line14.Layer = refin;
                line14.Lineweight = Lineweight.W35;
                dxf.AddEntity(line14);

                //中心线
                Line line15 = new Line(pzx, pzx2);
                line15.Linetype = Linetype.DashDot;
                line15.Layer = centre;
                line15.Lineweight = Lineweight.W25;
                dxf.AddEntity(line15);

                Line line16 = new Line(pzx1, pzx3);
                line16.Linetype = Linetype.DashDot;
                line16.Layer = centre;
                line16.Lineweight = Lineweight.W25;
                dxf.AddEntity(line16);

                Line line17 = new Line(pyz, pyz2);
                line17.Linetype = Linetype.DashDot;
                line17.Layer = centre;
                line17.Lineweight = Lineweight.W25;
                dxf.AddEntity(line17);

                Line line18 = new Line(pyz3, pyz4);
                line18.Linetype = Linetype.DashDot;
                line18.Layer = centre;
                line18.Lineweight = Lineweight.W25;
                dxf.AddEntity(line18);





                //外轮廓弧
                Arc arc1 = fun.DrawArc(p8, p1p, p6);
                fun.drawBArc(dxf, arc1, 0.5, contour);
                Arc arc2 = fun.DrawArc(p18, p5p, p10);
                fun.drawBArc(dxf, arc2, 0.5, contour);
                Arc arc3 = fun.DrawArc(p19, p4p, p11);
                fun.drawBArc(dxf, arc3, 0.5, contour);
                Arc arc4 = fun.DrawArc(p20, p3p, p12);
                fun.drawBArc(dxf, arc4, 0.5, contour);
                Arc arc5 = fun.DrawArc(p21, p2p, p13);
                fun.drawBArc(dxf, arc5, 0.5, contour);

                /*
                  LwPolyline poly1 = new LwPolyline();
                  poly1.Vertexes.Add(new LwPolylineVertex(p));
                  poly1.Vertexes[2].Bulge = -Math.Tan((pi - epsr) / 4); 
                   poly1.Vertexes.Add(new LwPolylineVertex(p29));
                  fun.PolyFill(dxf, poly1, 0.4, contour);
                
                
                double gd = p1p.Y - p6.Y;
                double db = p8.X;
                double xb= System.Math.Sqrt(Math .Pow (gd,2)+Math.Pow (db,2));
                double jd = Math .Acos ((gd*gd+xb*xb-db*db)/(2*gd*xb));

                double xb1 = Math.Sqrt(Math.Pow(p8.X, 2) + Math.Pow(p8.Y, 2));
                double xb2= Math.Sqrt(Math.Pow(p10.X, 2) + Math.Pow(p10.Y, 2));
                double xb3= Math.Sqrt(Math.Pow(p10.X-p8.X , 2) + Math.Pow(p8.Y-p10.Y , 2));
                double jd2 = Math.Acos((xb1 * xb1 + xb2 * xb2 - xb3 * xb3) / (2 * xb1 * xb2));
                LwPolyline poly100 = new LwPolyline();
                poly100.Vertexes.Add(new LwPolylineVertex(p6));
                poly100.Vertexes[0].Bulge = Math.Tan((pi*2-jd*2) / -4);
                poly100.Vertexes.Add(new LwPolylineVertex(p8));
                poly100.Vertexes[1].Bulge = Math.Tan((jd2)/-4);
                poly100.Vertexes.Add(new LwPolylineVertex(p10));
                poly100.Vertexes.Add(new LwPolylineVertex(p18));
                poly100.Vertexes.Add(new LwPolylineVertex(p11));
                poly100.Vertexes.Add(new LwPolylineVertex(p19));
                poly100.Vertexes.Add(new LwPolylineVertex(p12));
                poly100.Vertexes.Add(new LwPolylineVertex(p20));
                poly100.Vertexes.Add(new LwPolylineVertex(p13));
                poly100.Vertexes.Add(new LwPolylineVertex(p21));
                poly100.Vertexes.Add(new LwPolylineVertex(p6));
                */

                //fun.PolyFill(dxf, poly100, 0.4, contour);
                //螺纹弧

                Arc arc6 = fun.DrawArc(p6, p0, p21);
                fun.drawBArc(dxf, arc6, 0.5, contour);
                Arc arc7 = fun.DrawArc(p13, p0, p20);
                fun.drawBArc(dxf, arc7, 0.5, contour);
                Arc arc8 = fun.DrawArc(p12, p0, p19);
                fun.drawBArc(dxf, arc8, 0.5, contour);
                Arc arc9 = fun.DrawArc(p11, p0, p18);
                fun.drawBArc(dxf, arc9, 0.5, contour);
                Arc arc10 = fun.DrawArc(p10, p0, p8);
                fun.drawBArc(dxf, arc10, 0.5, contour);

                Arc arc11 = fun.DrawArc(p7, p0, p25);
                fun.drawBArc(dxf, arc11, 0.5, contour);
                Arc arc12 = fun.DrawArc(p17, p0, p24);
                fun.drawBArc(dxf, arc12, 0.5, contour);
                Arc arc13 = fun.DrawArc(p16, p0, p23);
                fun.drawBArc(dxf, arc13, 0.5, contour);
                Arc arc14 = fun.DrawArc(p15, p0, p22);
                fun.drawBArc(dxf, arc14, 0.5, contour);
                Arc arc15 = fun.DrawArc(p14, p0, p9);
                fun.drawBArc(dxf, arc15, 0.5, contour);
                //最大两个弧度
                Arc arc16 = fun.DrawArc(p28, p0, p26);
                fun.drawBArc(dxf, arc16, 0.5, contour);
                Arc arc17 = fun.DrawArc(p46, p0, p45);
                fun.drawBArc(dxf, arc17, 0.5, contour);
                Circle circle1 = new Circle(new Vector3(0, 0, 0), D1 / 2);//圆
                circle1.Linetype = Linetype.Dashed;
                circle1.Lineweight = netDxf.Lineweight.W50;
                circle1.Layer = contour;
                dxf.AddEntity(circle1);


                Vector2 p106 = fun.Polar(p0, pi, D1 / 2);
                Vector2 p206 = fun.Polar(p0, 0, D1 / 2);


                LwPolyline poly200 = new LwPolyline();
                poly200.Vertexes.Add(new LwPolylineVertex(p106));
                poly200.Vertexes[0].Bulge = Math.Tan(pi / 4);
                poly200.Vertexes.Add(new LwPolylineVertex(p206));
                poly200.Vertexes[1].Bulge = Math.Tan(pi / 4);
                poly200.Vertexes.Add(new LwPolylineVertex(p106));
                fun.PolyFill(dxf, poly200, 0.5, contour);

                //刨视图


                Vector2 p47 = fun.Polar(p0, pi / -2, D / 2);
                Vector2 p48 = fun.Polar(p47, 0, D + d);
                Vector2 pzstd = fun.Polar(p0, pi / -2, D1 / 2);
                //跟进一条
                Vector2 pgj = fun.Polar(p48, pi / 2, a);
                Vector2 p49 = fun.Polar(pzstd, 0, D + d);

                //镜像用的中分线
                Vector2 pjx = fun.Polar(p48, 0, E1 / 2);
                Vector2 pjx1 = fun.Polar(pjx, pi / 2, D + D);
                Vector2 pjx2 = fun.Polar(pjx, pi / -2, D);


                Vector2 p50;
                Vector2 p51;
                Vector2 p52;
                Vector2 p53;
                Vector2 p54;
                Vector2 p55;
                Vector2 p56;
                Vector2 p68;
                Vector2 p69;
                Vector2 p70;
                Vector2 p71;
                Vector2 p72;
                Vector2 p73;
                Vector2 p76;
                Vector2 p77;
                Vector2 p78;
                Vector2 p79;
                Vector2 p80;
                Vector2 p81;
                Vector2 p82;
                Vector2 p83;
                Vector2 p84;
                Vector2 p85;
                Vector2 p86;
                Vector2 p87;
                if (ajj > 45)
                {
                    p50 = fun.Polar(p49, pi / 2, D1 / 4);
                    p51 = fun.Polar(p50, pi / 2, p);
                    p52 = fun.Polar(p48, pi / 2, D / 2);//中心点
                    p53 = fun.Polar(p52, pi / 2, (D1 / 2.0) * (1.0 / 3));
                    p54 = fun.Polar(p53, pi / 2, p);
                    p55 = fun.Polar(p52, pi / 2, (D1 / 2) * (2.0 / 3));
                    p56 = fun.Polar(p55, pi / 2, p);

                    //中间的镜像点
                    p68 = fun.mirrorpoint(p50, pjx1, pjx2);
                    p69 = fun.mirrorpoint(p51, pjx1, pjx2);
                    p70 = fun.mirrorpoint(p53, pjx1, pjx2);
                    p71 = fun.mirrorpoint(p54, pjx1, pjx2);
                    p72 = fun.mirrorpoint(p55, pjx1, pjx2);
                    p73 = fun.mirrorpoint(p56, pjx1, pjx2);

                    //中间的点
                    p76 = fun.Polar(p50, pi / 4, System.Math.Sqrt(2) * (E1 / 3));
                    p77 = fun.Polar(p76, 0, E1 * l);
                    p78 = fun.Polar(p76, pi / 2, p);
                    p79 = fun.Polar(p77, pi / 2, p);
                    p80 = fun.Polar(p53, -45 * pi / 180, System.Math.Sqrt(2) * (E1 / 3));
                    p81 = fun.Polar(p80, 0, E1 * l);
                    p82 = fun.Polar(p80, pi / 2, p);
                    p83 = fun.Polar(p81, pi / 2, p);

                    p84 = fun.Polar(p55, -45 * pi / 180, System.Math.Sqrt(2) * (E1 / 3));
                    p85 = fun.Polar(p84, 0, E1 * l);
                    p86 = fun.Polar(p84, pi / 2, p);
                    p87 = fun.Polar(p85, pi / 2, p);

                    LwPolyline poly11 = new LwPolyline();
                    poly11.Vertexes.Add(new LwPolylineVertex(p56));
                    poly11.Vertexes.Add(new LwPolylineVertex(p86));
                    poly11.Vertexes.Add(new LwPolylineVertex(p84));
                    poly11.Vertexes.Add(new LwPolylineVertex(p55));
                    poly11.Vertexes.Add(new LwPolylineVertex(p56));
                    fun.PolyFill(dxf, poly11, 0.35, contour);

                    LwPolyline poly12 = new LwPolyline();
                    poly12.Vertexes.Add(new LwPolylineVertex(p86));
                    poly12.Vertexes.Add(new LwPolylineVertex(p87));
                    poly12.Vertexes.Add(new LwPolylineVertex(p85));
                    poly12.Vertexes.Add(new LwPolylineVertex(p84));
                    poly12.Vertexes.Add(new LwPolylineVertex(p86));
                    fun.PolyFill(dxf, poly12, 0.35, contour);

                    LwPolyline poly13 = new LwPolyline();
                    poly13.Vertexes.Add(new LwPolylineVertex(p87));
                    poly13.Vertexes.Add(new LwPolylineVertex(p73));
                    poly13.Vertexes.Add(new LwPolylineVertex(p72));
                    poly13.Vertexes.Add(new LwPolylineVertex(p85));
                    poly13.Vertexes.Add(new LwPolylineVertex(p87));
                    fun.PolyFill(dxf, poly13, 0.35, contour);

                }
                else
                {

                    if (drjj == 1 && l == 1)
                    {
                        drjj = 0 * pi / 180;
                        l = (1.0 / 3) * E1;

                    }
                    else if (drjj == 1 && l == 3)
                    {
                        drjj = 45.0 / 4 * pi / 180;
                        l = (9.0 / 10 * E1) / (Math.Cos(drjj));


                    }
                    else if (drjj == 1 && l == 2)
                    {
                        drjj = 0 * pi / 180;
                        l = (4.0 / 5) * E1;
                    }


                    p50 = fun.Polar(p49, pi / 2, D1 / 4);
                    p51 = fun.Polar(p50, pi / 2, p);
                    p52 = fun.Polar(p48, pi / 2, D / 2);//中心点
                    p53 = fun.Polar(p52, pi / 2, (D1 / 2.0) * (1.0 / 3));
                    p54 = fun.Polar(p53, pi / 2, p);
                    //中间的镜像点
                    p68 = fun.mirrorpoint(p50, pjx1, pjx2);
                    p69 = fun.mirrorpoint(p51, pjx1, pjx2);
                    p70 = fun.mirrorpoint(p53, pjx1, pjx2);
                    p71 = fun.mirrorpoint(p54, pjx1, pjx2);
                    //中间的点

                    p76 = fun.Polar(p50, 45 * pi / 180, System.Math.Sqrt(2) * (E1 / 10));
                    p77 = fun.Polar(p76, (0 * pi / 180 + drjj), (l));
                    p78 = fun.Polar(p76, pi / 2, p);
                    p79 = fun.Polar(p77, pi / 2, p);
                    p80 = fun.Polar(p53, -45 * pi / 180, System.Math.Sqrt(2) * (E1 / 10));
                    p81 = fun.Polar(p80, (0 * pi / 180 - drjj), (l));
                    p82 = fun.Polar(p80, pi / 2, p);
                    p83 = fun.Polar(p81, pi / 2, p);

                }


                Vector2 p57 = fun.Polar(p52, pi / 2, D1 / 2);
                Vector2 p58 = fun.Polar(p52, pi / 2, D / 2);
                Vector2 pdy = fun.Polar(p58, 0, E - a);
                Vector2 pdy1 = new Vector2(p58.X + E, p58.Y - a);
                Vector2 p59 = fun.Polar(p58, 0, E);
                Vector2 p60 = new Vector2(p59.X, p52.Y + DD1 / 2);
                Vector2 p61 = fun.Polar(p60, pi / -2, DD1);
                //临时加的
                Vector2 pdj = new Vector2(p48.X + E, p48.Y + a);
                Vector2 p62 = new Vector2(p61.X - a, p48.Y);
                Vector2 p63 = fun.Polar(p48, 0, (E / 2) + (b / 2));
                Vector2 p64 = fun.Polar(p63, pi, b);
                Vector2 p65 = fun.Polar(p48, 0, a);

                //刨切线
                Vector2 p109 = fun.Polar(p58, pi / 2, 2);
                Text txt2 = new Text("A-A", p109, 2.5, 2);
                dxf.AddEntity(txt2);


                //右边的框
                Vector2 p66 = fun.Polar(p60, pi, E - E1);
                Vector2 p67 = fun.Polar(p66, pi / -2, DD1);
                Vector2 pjxx = fun.Polar(p48, 0, E1 / 2);
                Vector2 pjxx1 = fun.Polar(pjxx, pi / 2, D);
                Vector2 p100 = fun.mirrorpoint(p57, pjxx, pjxx1);
                Vector2 p110 = fun.mirrorpoint(p49, pjxx, pjxx1);












                //下面的三角形顶点
                Vector2 p88 = fun.Polar(p63, 135 * pi / 180, b * (1 / System.Math.Sqrt(2)));

                if (sh == 0)
                {
                    LwPolyline poly20 = new LwPolyline();
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    poly20.Vertexes.Add(new LwPolylineVertex(p88));
                    poly20.Vertexes.Add(new LwPolylineVertex(p64));
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    fun.PolyFill(dxf, poly20, 0.5, contour);

                }
                else
                {
                    LwPolyline poly20 = new LwPolyline();
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    poly20.Vertexes.Add(new LwPolylineVertex(p88));
                    poly20.Vertexes.Add(new LwPolylineVertex(p64));
                    poly20.Vertexes[2].Bulge = Math.Tan((90 * pi / 180) / -4);
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    fun.PolyFill(dxf, poly20, 0.5, contour);
                }




                //中心线
                Vector2 p89 = fun.Polar(p52, pi, b);
                Vector2 p90 = fun.Polar(p89, 0, E + 2 * b);
                Line line100 = new Line(p89, p90);
                line100.Linetype = Linetype.DashDot;
                line100.Layer = centre;
                line100.Lineweight = Lineweight.W25;
                dxf.AddEntity(line100);



                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p49));
                poly1.Vertexes.Add(new LwPolylineVertex(p57));
                poly1.Vertexes.Add(new LwPolylineVertex(p100));
                poly1.Vertexes.Add(new LwPolylineVertex(p110));
                poly1.Vertexes.Add(new LwPolylineVertex(p49));
                fun.PolyFill(dxf, poly1, 0.5, contour);



                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p60));
                poly2.Vertexes.Add(new LwPolylineVertex(p66));
                poly2.Vertexes.Add(new LwPolylineVertex(p67));
                poly2.Vertexes.Add(new LwPolylineVertex(p61));
                poly2.Vertexes.Add(new LwPolylineVertex(p60));
                fun.PolyFill(dxf, poly2, 0.5, contour);



                //倒圆角
                if (dj == 1)
                {
                    LwPolyline poly3 = new LwPolyline();
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    poly3.Vertexes.Add(new LwPolylineVertex(p58));
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy));
                    poly3.Vertexes[2].Bulge = Math.Tan((45 * pi / 180) / -4);
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy1));
                    poly3.Vertexes.Add(new LwPolylineVertex(p60));
                    poly3.Vertexes.Add(new LwPolylineVertex(p66));
                    poly3.Vertexes.Add(new LwPolylineVertex(p100));
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    //poly3.SetConstantWidth(0.05);
                    poly3.IsClosed = true;
                    fun.PolyFill(dxf, poly3, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    Arc[] harc3 = new Arc[100];
                    int hnumst3 = poly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = poly3.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)poly3.Explode()[i];
                        }
                        if (htype3[i] == "Arc")
                        {
                            harc3[i] = (Arc)poly3.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype3, hnumst3, 45, 1, hline3, harc3, hatching);


                    LwPolyline poly4 = new LwPolyline();
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));
                    poly4.Vertexes.Add(new LwPolylineVertex(p49));
                    poly4.Vertexes.Add(new LwPolylineVertex(p110));
                    poly4.Vertexes.Add(new LwPolylineVertex(p67));
                    poly4.Vertexes.Add(new LwPolylineVertex(p61));
                    poly4.Vertexes.Add(new LwPolylineVertex(pdj));

                    poly4.Vertexes[5].Bulge = Math.Tan((45 * pi / 180) / -4);

                    poly4.Vertexes.Add(new LwPolylineVertex(p62));
                    poly4.Vertexes.Add(new LwPolylineVertex(p63));
                    poly4.Vertexes.Add(new LwPolylineVertex(p88));
                    poly4.Vertexes.Add(new LwPolylineVertex(p64));
                    poly4.Vertexes.Add(new LwPolylineVertex(p65));
                    poly4.Vertexes[10].Bulge = Math.Tan((45 * pi / 180) / -4);
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));

                    //poly4.SetConstantWidth(0.05);
                    poly4.IsClosed = true;
                    fun.PolyFill(dxf, poly4, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype4 = new String[100];
                    Line[] hline4 = new Line[100];
                    Arc[] harc4 = new Arc[100];
                    int hnumst4 = poly4.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst4; i++)
                    {
                        htype4[i] = poly4.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype4[i] == "Line")
                        {
                            hline4[i] = (Line)poly4.Explode()[i];
                        }
                        if (htype4[i] == "Arc")
                        {
                            harc4[i] = (Arc)poly4.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype4, hnumst4, 45, 1, hline4, harc4, hatching);
                }


                //倒斜角
                else
                {

                    LwPolyline poly3 = new LwPolyline();
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    Vector2 p1000 = fun.Polar(p58, pi / -2, a);
                    poly3.Vertexes.Add(new LwPolylineVertex(p1000));
                    Vector2 p1001 = fun.Polar(p58, 0, a);
                    poly3.Vertexes.Add(new LwPolylineVertex(p1001));
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy));
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy1));
                    poly3.Vertexes.Add(new LwPolylineVertex(p60));
                    poly3.Vertexes.Add(new LwPolylineVertex(p66));
                    poly3.Vertexes.Add(new LwPolylineVertex(p100));
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    //poly3.SetConstantWidth(0.05);
                    poly3.IsClosed = true;
                    fun.PolyFill(dxf, poly3, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    Arc[] harc3 = new Arc[100];
                    int hnumst3 = poly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = poly3.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)poly3.Explode()[i];
                        }
                        if (htype3[i] == "Arc")
                        {
                            harc3[i] = (Arc)poly3.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype3, hnumst3, 45, 1, hline3, harc3, hatching);


                    LwPolyline poly4 = new LwPolyline();
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));
                    poly4.Vertexes.Add(new LwPolylineVertex(p49));
                    poly4.Vertexes.Add(new LwPolylineVertex(p110));
                    poly4.Vertexes.Add(new LwPolylineVertex(p67));
                    poly4.Vertexes.Add(new LwPolylineVertex(p61));
                    poly4.Vertexes.Add(new LwPolylineVertex(pdj));
                    poly4.Vertexes.Add(new LwPolylineVertex(p62));
                    poly4.Vertexes.Add(new LwPolylineVertex(p63));
                    poly4.Vertexes.Add(new LwPolylineVertex(p88));
                    poly4.Vertexes.Add(new LwPolylineVertex(p64));
                    poly4.Vertexes.Add(new LwPolylineVertex(p65));
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));
                    //poly4.SetConstantWidth(0.05);
                    poly4.IsClosed = true;
                    fun.PolyFill(dxf, poly4, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype4 = new String[100];
                    Line[] hline4 = new Line[100];
                    Arc[] harc4 = new Arc[100];
                    int hnumst4 = poly4.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst4; i++)
                    {
                        htype4[i] = poly4.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype4[i] == "Line")
                        {
                            hline4[i] = (Line)poly4.Explode()[i];
                        }
                        if (htype4[i] == "Arc")
                        {
                            harc4[i] = (Arc)poly4.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype4, hnumst4, 45, 1, hline4, harc4, hatching);
                }
                LwPolyline poly5 = new LwPolyline();
                poly5.Vertexes.Add(new LwPolylineVertex(p50));
                poly5.Vertexes.Add(new LwPolylineVertex(p51));
                poly5.Vertexes.Add(new LwPolylineVertex(p78));
                poly5.Vertexes.Add(new LwPolylineVertex(p76));
                poly5.Vertexes.Add(new LwPolylineVertex(p50));
                fun.PolyFill(dxf, poly5, 0.35, contour);

                LwPolyline poly6 = new LwPolyline();
                poly6.Vertexes.Add(new LwPolylineVertex(p78));
                poly6.Vertexes.Add(new LwPolylineVertex(p79));
                poly6.Vertexes.Add(new LwPolylineVertex(p77));
                poly6.Vertexes.Add(new LwPolylineVertex(p76));
                poly6.Vertexes.Add(new LwPolylineVertex(p78));
                fun.PolyFill(dxf, poly6, 0.35, contour);

                LwPolyline poly7 = new LwPolyline();
                poly7.Vertexes.Add(new LwPolylineVertex(p79));
                poly7.Vertexes.Add(new LwPolylineVertex(p69));
                poly7.Vertexes.Add(new LwPolylineVertex(p68));
                poly7.Vertexes.Add(new LwPolylineVertex(p77));
                poly7.Vertexes.Add(new LwPolylineVertex(p79));
                fun.PolyFill(dxf, poly7, 0.35, contour);

                LwPolyline poly8 = new LwPolyline();
                poly8.Vertexes.Add(new LwPolylineVertex(p53));
                poly8.Vertexes.Add(new LwPolylineVertex(p54));
                poly8.Vertexes.Add(new LwPolylineVertex(p82));
                poly8.Vertexes.Add(new LwPolylineVertex(p80));
                poly8.Vertexes.Add(new LwPolylineVertex(p53));
                fun.PolyFill(dxf, poly8, 0.35, contour);

                LwPolyline poly9 = new LwPolyline();
                poly9.Vertexes.Add(new LwPolylineVertex(p82));
                poly9.Vertexes.Add(new LwPolylineVertex(p83));
                poly9.Vertexes.Add(new LwPolylineVertex(p81));
                poly9.Vertexes.Add(new LwPolylineVertex(p80));
                poly9.Vertexes.Add(new LwPolylineVertex(p82));
                fun.PolyFill(dxf, poly9, 0.35, contour);

                LwPolyline poly10 = new LwPolyline();
                poly10.Vertexes.Add(new LwPolylineVertex(p83));
                poly10.Vertexes.Add(new LwPolylineVertex(p71));
                poly10.Vertexes.Add(new LwPolylineVertex(p70));
                poly10.Vertexes.Add(new LwPolylineVertex(p81));
                poly10.Vertexes.Add(new LwPolylineVertex(p83));
                fun.PolyFill(dxf, poly10, 0.35, contour);




                //标注
                Vector2 p1004 = fun.Polar(p0, pi / 2, D / 2);
                Vector2 p1005 = fun.Polar(p48, 0, E / 2);
                fun.jdbz2(dxf, new Line(p0, p31), new Line(p0, p1004), D - 1, 2.5, 2, 2.5, "45", "", "");
                fun.jdbz2(dxf, new Line(p0, p1004), new Line(p0, p32), D - 1, 2.5, 2, 2.5, "45", "", "");
                fun.jdbz2(dxf, new Line(p34, p44), new Line(p34, p43), (D - D1 / 2 - 1), 2.5, 2, 2.5, "90", "", "");
                fun.dimrot1(dxf, p0, p35, -45, D / 2, 5, 2.5, 2, 0.9, "c=" + c, "", "");
                fun.dimrot1(dxf, p0, p38, 45, D / 2, 5, 2.5, 2, 0.9, "c=" + c, "", "");


                fun.dimrot1(dxf, p58, p66, 0, D / 2, 5, 2.5, 2, 0.9, "E1=" + E1, "", "");
                fun.dimrot1(dxf, p58, p60, 0, D, 5, 2.5, 2, 0.9, "E=" + E, "", "");
                fun.dimrot1(dxf, p58, p48, -90, D, 5, 2.5, 2, 0.9, "D=" + D, "", "");
                //fun.dimrot1(dxf, p66, p67, -90, D/2, 5, 2.5, 2, 0.9, "D1", "", "");
                fun.dimrot1(dxf, p48, p65, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p62, p61, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p48, p1005, 180, D * 2, 5, 2.5, 2, 0.9, "0.5E", "", "");
                fun.dimrot1(dxf, fun.Polar(p48, 0, E / 2), fun.Polar(p48, pi, E / 2), 180, D / 2, 5, 2.5, 2, 0.9, "b=" + b, "", "");



















            }


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }


        public static void Hexagonal(Dictionary<string, Object> data)  //六方板牙
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层

            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            /*
            double d = 7.723;
            double p = 0.907;
            double b = 5;
            double D = 25;
            double DD1= D - (b/2+(6*System.Math.Sqrt(2)*Math.Tan (6*pi /180)));
            double D1 = D - ((b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180)))*2);
            double E = 10;
            double E1 = 1 ;
            double s = 21;
            double l = ((s / 2 / Math.Cos(30 * pi / 180)));




            double c = 0.8;
            double a = 0.5;
            Vector2 pzk = new Vector2(0, 0);
            Vector2 pzk1 = fun.Polar(pzk,pi/2,(d/2)-p);
            double d1 = 0.1+(D1 /2)-(d/2-p );//排泄孔
            double ajj = 20;
            double dj =1;
            
            double drjj =1;
            double sh = 0;
            */

            double d = Convert.ToDouble(data["td"]);
            double p = Convert.ToDouble(data["tp"]);
            double b = Convert.ToDouble(data["tdz"]);
            double D = Convert.ToDouble(data["bd"]);
            double DD1 = D - (b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180)));
            double D1 = D - ((b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180))) * 2);
            double E = Convert.ToDouble(data["oal"]);
            // double E1 = E * 3/5;
            double s = Convert.ToDouble(data["drvs"]);
            double d1 = 0.1 + (D1 / 2) - (d / 2 - p);//排泄孔            
            double yx = (d / 2 - p);
            double yx2 = d / 2;
            double zxj = (D1 / 2) - (d1 / 2);
            double jd1 = (d1 / 2);
            double kc = 85 * pi / 180;
            double l = ((s / 2 / Math.Cos(30 * pi / 180)));


            //double E1 = (8 / 9 * E);

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p1 = fun.Polar(p0, pi / 2, D1 / 2);
            Vector2 p1p = fun.Polar(p1, pi / -2, d1 / 2);
            Vector2 p2 = fun.Polar(p0, pi / 2 + 72 * pi / 180, D1 / 2);
            Vector2 p2p = fun.Polar(p2, -18 * pi / 180, d1 / 2);
            Vector2 p3 = fun.Polar(p0, 234 * pi / 180, D1 / 2);
            Vector2 p3p = fun.Polar(p3, 54 * pi / 180, d1 / 2);
            Vector2 p4 = fun.Polar(p0, 306 * pi / 180, D1 / 2);
            Vector2 p4p = fun.Polar(p4, 126 * pi / 180, d1 / 2);
            Vector2 p5 = fun.Polar(p0, 18 * pi / 180, D1 / 2);
            Vector2 p5p = fun.Polar(p5, -162 * pi / 180, d1 / 2);
            Vector2 p6 = fun.Polar(p0, pi * 0.5 + Math.Acos((yx * yx + zxj * zxj - jd1 * jd1) / (2 * yx * zxj)), yx);

            Vector2 p7 = fun.Polar(p0, pi / 2 + Math.Acos((yx2 * yx2 + zxj * zxj - jd1 * jd1) / (2 * yx2 * zxj)), yx2);
            Vector2 pz = fun.Polar(p0, pi / 2, D);
            Vector2 pz1 = fun.Polar(p0, pi / -2, D);
            Vector2 p8 = fun.mirrorpoint(p6, pz, pz1);
            Vector2 p9 = fun.mirrorpoint(p7, pz, pz1);





            //六边形六点
            Vector2 p31 = fun.Polar(p0, pi / -2, l);
            Vector2 p32 = fun.Polar(p31, 150 * pi / 180, l);
            Vector2 p33 = fun.Polar(p32, pi / 2, l);
            Vector2 p34 = fun.Polar(p33, pi / 6, l);
            Vector2 p35 = fun.Polar(p34, pi / -6, l);
            Vector2 p36 = fun.Polar(p35, pi / -2, l);



            //中心线

            Vector2 pyz = fun.Polar(p0, 0, D);
            Vector2 pyz2 = fun.Polar(p0, pi, D);
            Vector2 pyz3 = fun.Polar(p0, pi / 2, D);
            Vector2 pyz4 = fun.Polar(p0, pi / -2, D);



            var p10 = fun.PointRotate(p0, p6, 72 * pi / 180);
            var p11 = fun.PointRotate(p0, p6, 144 * pi / 180);
            var p12 = fun.PointRotate(p0, p6, 216 * pi / 180);
            var p13 = fun.PointRotate(p0, p6, 288 * pi / 180);
            var p14 = fun.PointRotate(p0, p7, 72 * pi / 180);
            var p15 = fun.PointRotate(p0, p7, 144 * pi / 180);
            var p16 = fun.PointRotate(p0, p7, 216 * pi / 180);
            var p17 = fun.PointRotate(p0, p7, 288 * pi / 180);
            var p18 = fun.PointRotate(p0, p8, 72 * pi / 180);
            var p19 = fun.PointRotate(p0, p8, 144 * pi / 180);
            var p20 = fun.PointRotate(p0, p8, 216 * pi / 180);
            var p21 = fun.PointRotate(p0, p8, 288 * pi / 180);
            var p22 = fun.PointRotate(p0, p9, 72 * pi / 180);
            var p23 = fun.PointRotate(p0, p9, 144 * pi / 180);
            var p24 = fun.PointRotate(p0, p9, 216 * pi / 180);
            var p25 = fun.PointRotate(p0, p9, 288 * pi / 180);








            Line line17 = new Line(pyz, pyz2);
            line17.Linetype = Linetype.DashDot;
            line17.Layer = centre;
            line17.Lineweight = Lineweight.W25;
            dxf.AddEntity(line17);

            Line line18 = new Line(pyz3, pyz4);
            line18.Linetype = Linetype.DashDot;
            line18.Layer = centre;
            line18.Lineweight = Lineweight.W25;
            dxf.AddEntity(line18);





            //外轮廓弧
            Arc arc1 = fun.DrawArc(p8, p1p, p6);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            Arc arc2 = fun.DrawArc(p18, p5p, p10);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            Arc arc3 = fun.DrawArc(p19, p4p, p11);
            fun.drawBArc(dxf, arc3, 0.5, contour);
            Arc arc4 = fun.DrawArc(p20, p3p, p12);
            fun.drawBArc(dxf, arc4, 0.5, contour);
            Arc arc5 = fun.DrawArc(p21, p2p, p13);
            fun.drawBArc(dxf, arc5, 0.5, contour);




            double gd = p1p.Y - p6.Y;
            double db = p8.X;
            double xb = System.Math.Sqrt(Math.Pow(gd, 2) + Math.Pow(db, 2));
            double jd = Math.Acos((gd * gd + xb * xb - db * db) / (2 * gd * xb));

            double xb1 = Math.Sqrt(Math.Pow(p8.X, 2) + Math.Pow(p8.Y, 2));
            double xb2 = Math.Sqrt(Math.Pow(p10.X, 2) + Math.Pow(p10.Y, 2));
            double xb3 = Math.Sqrt(Math.Pow(p10.X - p8.X, 2) + Math.Pow(p8.Y - p10.Y, 2));
            double jd2 = Math.Acos((xb1 * xb1 + xb2 * xb2 - xb3 * xb3) / (2 * xb1 * xb2));
            LwPolyline poly100 = new LwPolyline();
            poly100.Vertexes.Add(new LwPolylineVertex(p6));
            poly100.Vertexes[0].Bulge = Math.Tan((pi * 2 - jd * 2) / -4);
            poly100.Vertexes.Add(new LwPolylineVertex(p8));
            poly100.Vertexes[1].Bulge = Math.Tan((jd2) / -4);
            poly100.Vertexes.Add(new LwPolylineVertex(p10));
            poly100.Vertexes.Add(new LwPolylineVertex(p18));
            poly100.Vertexes.Add(new LwPolylineVertex(p11));
            poly100.Vertexes.Add(new LwPolylineVertex(p19));
            poly100.Vertexes.Add(new LwPolylineVertex(p12));
            poly100.Vertexes.Add(new LwPolylineVertex(p20));
            poly100.Vertexes.Add(new LwPolylineVertex(p13));
            poly100.Vertexes.Add(new LwPolylineVertex(p21));
            poly100.Vertexes.Add(new LwPolylineVertex(p6));


            //fun.PolyFill(dxf, poly100, 0.4, contour);
            //螺纹弧

            Arc arc6 = fun.DrawArc(p6, p0, p21);
            fun.drawBArc(dxf, arc6, 0.5, contour);
            Arc arc7 = fun.DrawArc(p13, p0, p20);
            fun.drawBArc(dxf, arc7, 0.5, contour);
            Arc arc8 = fun.DrawArc(p12, p0, p19);
            fun.drawBArc(dxf, arc8, 0.5, contour);
            Arc arc9 = fun.DrawArc(p11, p0, p18);
            fun.drawBArc(dxf, arc9, 0.5, contour);
            Arc arc10 = fun.DrawArc(p10, p0, p8);
            fun.drawBArc(dxf, arc10, 0.5, contour);

            Arc arc11 = fun.DrawArc(p7, p0, p25);
            fun.drawBArc(dxf, arc11, 0.5, contour);
            Arc arc12 = fun.DrawArc(p17, p0, p24);
            fun.drawBArc(dxf, arc12, 0.5, contour);
            Arc arc13 = fun.DrawArc(p16, p0, p23);
            fun.drawBArc(dxf, arc13, 0.5, contour);
            Arc arc14 = fun.DrawArc(p15, p0, p22);
            fun.drawBArc(dxf, arc14, 0.5, contour);
            Arc arc15 = fun.DrawArc(p14, p0, p9);
            fun.drawBArc(dxf, arc15, 0.5, contour);

            //最大两个弧度

            Circle circle1 = new Circle(new Vector3(0, 0, 0), s / 2);//圆
            circle1.Linetype = Linetype.Dashed;
            circle1.Lineweight = netDxf.Lineweight.W50;
            circle1.Layer = contour;
            dxf.AddEntity(circle1);

            //内接圆

            Vector2 p106 = fun.Polar(p0, pi, s / 2);
            Vector2 p206 = fun.Polar(p0, 0, s / 2);


            LwPolyline poly200 = new LwPolyline();
            poly200.Vertexes.Add(new LwPolylineVertex(p106));
            poly200.Vertexes[0].Bulge = Math.Tan(pi / 4);
            poly200.Vertexes.Add(new LwPolylineVertex(p206));
            poly200.Vertexes[1].Bulge = Math.Tan(pi / 4);
            poly200.Vertexes.Add(new LwPolylineVertex(p106));
            fun.PolyFill(dxf, poly200, 0.5, contour);




            //刨视图
            Vector2 p47 = fun.Polar(p0, pi / -2, l);
            Vector2 p48 = fun.Polar(p47, 0, s + s / 2);
            //镜像线
            Vector2 jxx = fun.Polar(p48, 0, E / 2);
            Vector2 jxx1 = fun.Polar(jxx, pi / 2, l * 2 + l);

            Vector2 p49 = fun.Polar(p48, pi / 2, E / 10);
            Vector2 p50 = fun.Polar(p49, pi / 2, (l * 2) - (E / 5));
            Vector2 p51 = fun.Polar(p50, pi / 2, E / 10);
            Vector2 p52 = fun.Polar(p51, 0, E / 10);
            Vector2 p53 = fun.mirrorpoint(p52, jxx, jxx1);
            Vector2 p54 = fun.mirrorpoint(p51, jxx, jxx1);
            Vector2 p55 = fun.mirrorpoint(p50, jxx, jxx1);
            Vector2 p56 = fun.mirrorpoint(p49, jxx, jxx1);
            Vector2 p57 = fun.mirrorpoint(p48, jxx, jxx1);


            Vector2 p58 = fun.Polar(p57, pi, E / 10);
            Vector2 p59 = fun.Polar(p48, 0, E / 10);




            //刨视图中间的点
            Vector2 p60 = fun.Polar(p59, pi / 2, (((l * 2) - l) / 2));
            Vector2 p61 = fun.mirrorpoint(p60, jxx, jxx1);
            Vector2 p62 = fun.Polar(p60, pi / 2, l);
            Vector2 p63 = fun.mirrorpoint(p62, jxx, jxx1); ;


            //刨视图中线
            Vector2 p64 = fun.Polar(p48, pi / 2, l);
            Vector2 p65 = fun.Polar(p64, pi, 5);
            Vector2 p66 = fun.Polar(p65, 0, E + 10);

            //连线
            //六边形
            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p31));
            poly1.Vertexes.Add(new LwPolylineVertex(p32));
            poly1.Vertexes.Add(new LwPolylineVertex(p33));
            poly1.Vertexes.Add(new LwPolylineVertex(p34));
            poly1.Vertexes.Add(new LwPolylineVertex(p35));
            poly1.Vertexes.Add(new LwPolylineVertex(p36));
            poly1.Vertexes.Add(new LwPolylineVertex(p31));
            fun.PolyFill(dxf, poly1, 0.3, contour);


            //刨视图
            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p49));
            poly2.Vertexes.Add(new LwPolylineVertex(p50));
            poly2.Vertexes.Add(new LwPolylineVertex(p52));
            poly2.Vertexes.Add(new LwPolylineVertex(p53));
            poly2.Vertexes.Add(new LwPolylineVertex(p55));
            poly2.Vertexes.Add(new LwPolylineVertex(p56));
            poly2.Vertexes.Add(new LwPolylineVertex(p58));
            poly2.Vertexes.Add(new LwPolylineVertex(p59));
            poly2.Vertexes.Add(new LwPolylineVertex(p49));
            fun.PolyFill(dxf, poly2, 0.3, contour);


            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p59));
            poly3.Vertexes[0].Bulge = -Math.Tan((73 * pi / 180) / 4);
            poly3.Vertexes.Add(new LwPolylineVertex(p60));
            poly3.Vertexes.Add(new LwPolylineVertex(p61));
            poly3.Vertexes[2].Bulge = -Math.Tan((73 * pi / 180) / 4);
            poly3.Vertexes.Add(new LwPolylineVertex(p58));
            poly3.Vertexes.Add(new LwPolylineVertex(p59));
            fun.PolyFill(dxf, poly3, 0.3, contour);


            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(p60));
            poly4.Vertexes[0].Bulge = -Math.Tan((37 * pi / 180) / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(p62));
            poly4.Vertexes.Add(new LwPolylineVertex(p63));
            poly4.Vertexes[2].Bulge = -Math.Tan((37 * pi / 180) / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(p61));
            poly4.Vertexes.Add(new LwPolylineVertex(p60));
            fun.PolyFill(dxf, poly4, 0.3, contour);


            LwPolyline poly5 = new LwPolyline();
            poly5.Vertexes.Add(new LwPolylineVertex(p62));
            poly5.Vertexes[0].Bulge = -Math.Tan((73 * pi / 180) / 4);
            poly5.Vertexes.Add(new LwPolylineVertex(p52));
            poly5.Vertexes.Add(new LwPolylineVertex(p53));
            poly5.Vertexes[2].Bulge = -Math.Tan((73 * pi / 180) / 4);
            poly5.Vertexes.Add(new LwPolylineVertex(p63));
            poly5.Vertexes.Add(new LwPolylineVertex(p62));
            fun.PolyFill(dxf, poly5, 0.3, contour);

            //中心线
            Line line20 = new Line(p65, p66);
            line20.Linetype = Linetype.DashDot;
            line20.Layer = centre;
            line20.Lineweight = Lineweight.W25;
            dxf.AddEntity(line20);

            Vector2 p67 = fun.Polar(p33, 210 * pi / 180, l * 2);
            Vector2 p68 = fun.Polar(p32, pi / 2, l);
            Vector2 p69 = fun.Polar(p33, pi / 2, l * 2);

            fun.jdbz2(dxf, new Line(p68, p69), new Line(p68, p67), l * 2, 2.5, 2, 2.5, "120", "", "");
            fun.dimrot1(dxf, p32, p36, 180, l * 2, 5, 2.5, 2, 0.9, "s=" + s, "", "");
            fun.dimrot1(dxf, p48, p57, 180, l * 2, 5, 2.5, 2, 0.9, "  E=" + E, "", "");




            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }



        public static void ThreadCuttingDieHexagonalShape(Dictionary<string, Object> data)  //六角板牙
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            double pi = Math.PI;

            double oal = Convert.ToDouble(data["oal"]);
            double td = Convert.ToDouble(data["td"]);
            double drvs = Convert.ToDouble(data["drvs"]);
            double tp = Convert.ToDouble(data["tp"]);
            string path = Convert.ToString(data["path"]);


            double le = drvs * 0.5 / Math.Sin(pi / 3);
            double td1 = td - 1.0825 * tp;
            double d1 = td / 2.2;

            /*
            double oal = 12;
            double td = 6;
            double drvs = 24;
            double tp = 1;
            string path = Convert.ToString(data["path"]);
            double DIM = 0;
            double le = drvs * 0.5 / Math.Sin(pi / 3);
            double td1 = td - 1.0825 * tp;
            double d1 = td / 2.2;
            */
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p1 = fun.Polar(p0, pi, le);
            Vector2 p2 = fun.Polar(p0, 4.0 / 3 * pi, le);
            Vector2 p3 = fun.Polar(p0, 5.0 / 3 * pi, le);
            Vector2 p4 = fun.Polar(p0, 0, le);
            Vector2 p5 = fun.Polar(p0, 1.0 / 3 * pi, le);
            Vector2 p6 = fun.Polar(p0, 2.0 / 3 * pi, le);

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            double ang1 = Math.Asin(d1 * 0.5 / td1);

            Vector2 p11 = fun.Polar(p0, pi - ang1, td1);
            Vector2 p12 = fun.Polar(p11, pi, 1.0825 * tp);
            Vector2 p13 = fun.Polar(p12, pi, 1.5 * tp);
            Vector2 p34 = new Vector2(p0.X - p11.X, p11.Y);
            Vector2 p33 = new Vector2(p0.X - p12.X, p12.Y);
            Vector2 p32 = new Vector2(p0.X - p13.X, p13.Y);
            Vector2 p14 = new Vector2(p13.X, p0.Y - p13.Y);
            Vector2 p15 = new Vector2(p12.X, p0.Y - p12.Y);
            Vector2 p16 = new Vector2(p11.X, p0.Y - p11.Y);
            Vector2 p29 = new Vector2(p34.X, p0.Y - p34.Y);
            Vector2 p30 = new Vector2(p33.X, p0.Y - p33.Y);
            Vector2 p31 = new Vector2(p32.X, p0.Y - p32.Y);

            Vector2 p41 = fun.Polar(p0, pi - ang1 - pi / 3, td1);
            Vector2 p42 = fun.Polar(p41, 2.0 / 3 * pi, 1.0825 * tp);
            Vector2 p43 = fun.Polar(p42, 2.0 / 3 * pi, 1.5 * tp);
            Vector2 p44 = fun.Polar(p43, 7.0 / 6 * pi, d1);
            Vector2 p45 = fun.Polar(p42, 7.0 / 6 * pi, d1);
            Vector2 p46 = fun.Polar(p41, 7.0 / 6 * pi, d1);
            Vector2 p35 = new Vector2(p0.X - p46.X, p46.Y);
            Vector2 p36 = new Vector2(p0.X - p45.X, p45.Y);
            Vector2 p37 = new Vector2(p0.X - p44.X, p44.Y);
            Vector2 p38 = new Vector2(p0.X - p43.X, p43.Y);
            Vector2 p39 = new Vector2(p0.X - p42.X, p42.Y);
            Vector2 p40 = new Vector2(p0.X - p41.X, p41.Y);

            Vector2 p17 = new Vector2(p46.X, p0.Y - p46.Y);
            Vector2 p18 = new Vector2(p45.X, p0.Y - p45.Y);
            Vector2 p19 = new Vector2(p44.X, p0.Y - p44.Y);
            Vector2 p20 = new Vector2(p43.X, p0.Y - p43.Y);
            Vector2 p21 = new Vector2(p42.X, p0.Y - p42.Y);
            Vector2 p22 = new Vector2(p41.X, p0.Y - p41.Y);
            Vector2 p23 = new Vector2(p40.X, p0.Y - p40.Y);
            Vector2 p24 = new Vector2(p39.X, p0.Y - p39.Y);
            Vector2 p25 = new Vector2(p38.X, p0.Y - p38.Y);
            Vector2 p26 = new Vector2(p37.X, p0.Y - p37.Y);
            Vector2 p27 = new Vector2(p36.X, p0.Y - p36.Y);
            Vector2 p28 = new Vector2(p35.X, p0.Y - p35.Y);

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p11));
            poly2.Vertexes.Add(new LwPolylineVertex(p13));
            poly2.Vertexes[1].Bulge = 1;
            poly2.Vertexes.Add(new LwPolylineVertex(p14));
            poly2.Vertexes.Add(new LwPolylineVertex(p16));
            poly2.Vertexes[3].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
            poly2.Vertexes.Add(new LwPolylineVertex(p17));
            poly2.Vertexes.Add(new LwPolylineVertex(p19));
            poly2.Vertexes[5].Bulge = 1;
            poly2.Vertexes.Add(new LwPolylineVertex(p20));
            poly2.Vertexes.Add(new LwPolylineVertex(p22));
            poly2.Vertexes[7].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
            poly2.Vertexes.Add(new LwPolylineVertex(p23));
            poly2.Vertexes.Add(new LwPolylineVertex(p25));
            poly2.Vertexes[9].Bulge = 1;
            poly2.Vertexes.Add(new LwPolylineVertex(p26));
            poly2.Vertexes.Add(new LwPolylineVertex(p28));
            poly2.Vertexes[11].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
            poly2.Vertexes.Add(new LwPolylineVertex(p29));
            poly2.Vertexes.Add(new LwPolylineVertex(p31));
            poly2.Vertexes[13].Bulge = 1;
            poly2.Vertexes.Add(new LwPolylineVertex(p32));
            poly2.Vertexes.Add(new LwPolylineVertex(p34));
            poly2.Vertexes[15].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
            poly2.Vertexes.Add(new LwPolylineVertex(p35));
            poly2.Vertexes.Add(new LwPolylineVertex(p37));
            poly2.Vertexes[17].Bulge = 1;
            poly2.Vertexes.Add(new LwPolylineVertex(p38));
            poly2.Vertexes.Add(new LwPolylineVertex(p40));
            poly2.Vertexes[19].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
            poly2.Vertexes.Add(new LwPolylineVertex(p41));
            poly2.Vertexes.Add(new LwPolylineVertex(p43));
            poly2.Vertexes[21].Bulge = 1;
            poly2.Vertexes.Add(new LwPolylineVertex(p44));
            poly2.Vertexes.Add(new LwPolylineVertex(p46));
            poly2.Vertexes[23].Bulge = Math.Tan((pi / 3 - ang1 * 2) / 4);
            poly2.Vertexes.Add(new LwPolylineVertex(p11));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            Arc arc1 = fun.DrawArc(p45, p0, p12);
            arc1.Layer = contour;
            dxf.AddEntity(arc1);
            Arc arc2 = fun.DrawArc(p15, p0, p18);
            arc2.Layer = contour;
            dxf.AddEntity(arc2);
            Arc arc3 = fun.DrawArc(p21, p0, p24);
            arc3.Layer = contour;
            dxf.AddEntity(arc3);
            Arc arc4 = fun.DrawArc(p27, p0, p30);
            arc4.Layer = contour;
            dxf.AddEntity(arc4);
            Arc arc5 = fun.DrawArc(p33, p0, p36);
            arc5.Layer = contour;
            dxf.AddEntity(arc5);
            Arc arc6 = fun.DrawArc(p39, p0, p42);
            arc6.Layer = contour;
            dxf.AddEntity(arc6);

            Vector2 po1 = new Vector2(p4.X + 48, p5.Y);
            Vector2 po2 = new Vector2(po1.X, p3.Y);
            Vector2 p1_ = new Vector2(po1.X, p1.Y);
            Vector2 p2_ = fun.Polar(p1_, 0, oal);
            Vector2 po3 = fun.Polar(po2, 0, oal);
            Vector2 po4 = new Vector2(po3.X, po1.Y);

            Line line1_ = new Line(p1_, p2_);
            fun.drawBline(dxf, line1_, 0.3, contour);


            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(po1));
            poly3.Vertexes.Add(new LwPolylineVertex(po2));
            poly3.Vertexes.Add(new LwPolylineVertex(po3));
            poly3.Vertexes.Add(new LwPolylineVertex(po4));
            poly3.Vertexes.Add(new LwPolylineVertex(po1));
            fun.PolyFill(dxf, poly3, 0.3, contour);

            Vector2[] cenline1 = { fun.Polar(p1, pi, 1), fun.Polar(p4, 0, 1) };
            fun.drawPlinetype(dxf, cenline1, 0.15, center, Linetype.Center);
            Vector2[] cenline2 = { new Vector2(po1.X - 1, p0.Y), new Vector2(po4.X + 1, p0.Y) };
            fun.drawPlinetype(dxf, cenline2, 0.15, center, Linetype.Center);
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 3.5;
            double offset = 7;






            Vector2 p50 = fun.Polar(po3, pi, (p3.X - p2.X) / 2.0);
            Vector2 p51 = fun.Polar(po3, pi / -2, drvs);
            Vector2 p52 = new Vector2(po1.X, p0.Y);
            Vector2 p53 = new Vector2(po4.X, p0.Y);
            Vector2 p54 = fun.Polar(p53, pi / 4, 0.1);
            Vector2 p55 = fun.Polar(p54, pi / 4, oal / 4.0);
            Vector2 p56 = fun.Polar(p55, pi / 2, 0.1);
            Vector2 p57 = fun.Polar(p52, pi + pi / 6, oal);
            Vector2 p58 = fun.Polar(p57, pi / -2, 0.1);
            Vector2 p59 = fun.Polar(p0, pi - pi / 6, drvs);
            Vector2 p60 = fun.Polar(p59, pi / 2, 0.5);
            Vector2 p61 = fun.Polar(p0, 0, td / 2.0);
            Vector2 p62 = fun.Polar(p61, pi / 6, drvs / 2.0 + 4);
            Vector2 p63 = fun.Polar(p62, pi / 2, 0.3);

            Vector2 p64 = fun.Polar(p0, pi / 4, td);
            Vector2 p65 = fun.Polar(p64, pi / 4, td);
            Vector2 p66 = fun.Polar(p65, pi / 4, 3);
            Vector2 p67 = new Vector2(po3.X + oal + 5, p51.Y);
            Vector2 p68 = new Vector2(po3.X + oal + 2.5, p51.Y);
            Vector2 p69 = new Vector2(po3.X + 5, p51.Y);
            fun.Axis(dxf, new Vector2(p0.X, p51.Y), 180, -90, "Y", "X", "Z", 0.5, 1.2, 0);
            fun.Axis(dxf, p0, 180, -90, "", "", "", 0.5, 1.2, 0);
            fun.Axis(dxf, p51, 180, -90, "Z", "X", "Y", 0.5, 1.2, 0);
            fun.Axis(dxf, p52, 180, -90, "", "", "", 0.5, 1.2, 0);
            fun.Axis(dxf, p53, 180, -90, "", "", "", 0.5, 1.2, 0);
            LinearDimension linedim2 = new LinearDimension(new Line(po1, po4), offset*1.5, 0, dimensionStyle);
            linedim2.UserText = "OAL，LF,LPR,LTA  ";
            dxf.AddEntity(linedim2);

            Circle circle1 = new Circle(p61, 1.7 * 0.5);
            Line line1 = new Line(p54, p55);
            Line line2 = new Line(p52, p57);
            Line line3 = new Line(p0, p59);
            Line line4 = new Line(p62, p61);
            Text txt1 = new Text("CIP,CRP", p56, 1.2, 0);
            Text txt2 = new Text("MCS,PCS", new Vector2 (p58.X -20,p58.Y ), 1.2, 0);
            Text txt3 = new Text("MCS,PCS,CIP", new Vector2 (p60.X-40,p60.Y  ), 1.2, 0);
            Text txt4 = new Text("CRP", new Vector2(p63.X, p63.Y - 3), 1.2, 0);
            Text txt5 = new Text("ISYC=301-06", fun.Polar(p4, pi / 2, drvs * 1.5), 1.2, 0);
            dxf.AddEntity(new EntityObject[] { circle1, line1, line2, line3, line4, txt1, txt2, txt3, txt4, txt5 });
            fun.Singlelinearrow(dxf, "TDZ", p64, 45, p65, p66, 1.2, 1.6);
            fun.Singlelinearrow(dxf, "FDP", new Vector2 (p67.X +8,p67.Y ), 0, p68, p69, 1.2, 1.6);

            LinearDimension linedim1 = new LinearDimension(new Line(p4, p6), offset * 3, 330, dimensionStyle);
            linedim1.UserText = "DRVS  ";
            dxf.AddEntity(linedim1);


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }
            fun.SetLayer(dxf);

            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }


        public static void Cutttap(Dictionary<string, Object> data)  //切削丝锥
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;
            double scale = 2;
            double tcl = 4 * scale;
            double td = 12.5 * scale;
            double tcpd = 8.5 * scale;
            double thl = 28 * scale;
            double oal = 60 * scale;
            double dmm = 7 * scale;

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p1 = fun.Polar(p0, pi / 2, tcpd / 2.0);
            Vector2 p2 = new Vector2(tcl, td / 2.0);
            Vector2 p3 = fun.Polar(p2, 0, thl - tcl);
            Vector2 p4 = fun.Inters(p1, fun.Polar(p1, 0, oal), p3, fun.Polar(p3, pi / -4, oal));
            Vector2 p5_1 = fun.Polar(p0, pi / 2, dmm / 2.0);
            Vector2 p5_2 = fun.Polar(p5_1, 0, oal);
            Vector2 p5 = fun.Inters(p4, fun.Polar(p4, pi / -6, oal), p5_1, p5_2);
            Vector2 p6 = fun.Polar(p0, pi / 2, tcpd / 2.0 / 3.0 / 2.0);
            Vector2 p7_1 = fun.Polar(p0, pi / 2, dmm / 4.0);
            Vector2 p7_2 = fun.Polar(p7_1, 0, oal);
            Vector2 p7 = fun.Inters(p6, fun.Polar(p6, 15 * pi / 180, oal), p7_1, p7_2);
            Vector2 p8 = fun.Inters(p5, fun.Polar(p5, pi / -6, oal), p7, fun.Polar(p7, 0, oal));

            Vector2 p9 = new Vector2(p1.X, -p1.Y);
            Vector2 p10 = new Vector2(p2.X, -p2.Y);
            Vector2 p11 = new Vector2(p3.X, -p3.Y);
            Vector2 p12 = new Vector2(p4.X, -p4.Y);
            Vector2 p13 = new Vector2(p5.X, -p5.Y);
            Vector2 p14 = new Vector2(p8.X, p13.Y);
            Vector2 p15 = new Vector2(p5.X, -(tcpd / 2.0 / 1.8));
            Vector2 p16 = fun.Polar(p0, pi / -2, -p15.Y);
            Vector2 p17 = fun.Inters(p3, fun.Polar(p3, pi / -2, oal), p7, p8);
            Vector2 p18 = fun.Inters(p16, p15, p3, fun.Polar(p3, pi / -2, oal));
            Vector2 p19 = new Vector2(oal, 0);
            Vector2 p20 = fun.Polar(p19, pi / 2, dmm / 2.0);
            Vector2 p21 = new Vector2(p20.X, -p20.Y);
            Vector2 p22 = new Vector2(p20.X, p20.Y - p20.Y / 8.0);
            Vector2 p23 = fun.Polar(p22, pi, (28 / 3.0) * (oal / 60.0));
            Vector2 p24 = new Vector2(p23.X, p20.Y - p22.Y);
            Vector2 p25 = new Vector2(p22.X, p24.Y);
            Vector2 p26 = new Vector2(p25.X, -p25.Y);
            Vector2 p27 = new Vector2(p24.X, -p24.Y);
            Vector2 p28 = new Vector2(p23.X, -p23.Y);
            Vector2 p29 = new Vector2(p22.X, -p22.Y);


            Vector2 arc1_1 = fun.Polar(p4, 0, 0.1 * (thl / 18.0));
            Vector2 arc1_2 = fun.Polar(p4, 120 * pi / 180, oal);
            Arc arc1 = fun.DrawArc5(p4, new Line(arc1_1, arc1_2), p3);
            Vector2 arc2_1 = fun.Polar(p4, pi, 0.05 * (thl / 18.0));
            Vector2 arc2_2 = fun.Polar(arc2_1, -50 * pi / 180, oal);
            Arc arc2 = fun.DrawArc5(p4, new Line(arc2_1, arc2_2), p5);
            Vector2 arc3_1 = fun.Polar(p5, pi / 2, 0.01);
            Vector2 arc3_2 = fun.Polar(arc3_1, 0.01 * pi / 180, oal);
            Arc arc3 = fun.DrawArc5(p8, new Line(arc3_1, arc3_2), p5);
            Arc arc4 = fun.DrawArc4(p11, arc1.Radius, p12, 0);
            Arc arc5 = fun.DrawArc4(p13, arc2.Radius, p12, 0);
            Arc arc6 = fun.DrawArc4(p14, arc3.Radius, p15, 0);
            Line line1 = new Line(p13, p14);
            var polyline1 = Pus.AddPointsToLwPolyLine(p3, p2, p1, p0, p6, p7, p8, p17, p18, p15, p16, p0, p9, p10, p11);
            var polyline2 = Pus.AddPointsToLwPolyLine(p5, p20, p21, p29, p28, p27, p26, p28, p27, p29, p25, p23, p24, p22, p23, p24, p25, p21, p14);
            //dxf.AddEntity(new EntityObject[] { arc1, arc2, arc3, arc4, arc5, arc6, polyline1,polyline2 ,line1 });
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.drawBline(dxf, line1, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            fun.drawBArc(dxf, arc3, 0.5, contour);
            fun.drawBArc(dxf, arc4, 0.5, contour);
            fun.drawBArc(dxf, arc5, 0.5, contour);
            fun.drawBArc(dxf, arc6, 0.5, contour);


            var polyline3 = Pus.AddPointsToLwPolyLine(p6, p7, p17, p18, p16, p6);
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = polyline3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = polyline3.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)polyline3.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)polyline3.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * (oal / 60.0), hline1, harc1, hatching);


            //标注
            double sch = (oal / 60.0);
            double offel = 5 * sch;

            fun.dimrot1(dxf, p1, p3, 0, (p3.Y - p1.Y) + offel, 2, 1.2 * sch, 1.6 * sch, 0.9, "THL", "", "");
            fun.dimrot1(dxf, p0, p19, 0, offel * 2 + p2.Y, 2, 1.2 * sch, 1.6 * sch, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p9, p10, 180, -(p10.Y - p9.Y) + offel, 2, 1.2 * sch, 1.6 * sch, 0.9, "TCL", "", "");
            fun.dimrot1(dxf, p1, p9, 90, offel, 2, 1.2 * sch, 1.6 * sch, 0.9, "TCPD", "", "");
            fun.dimrot1(dxf, p2, p10, 90, offel * 2.5, 2, 1.2 * sch, 1.6 * sch, 0.9, "TD", "", "");
            fun.dimrot1(dxf, p20, p21, -90, offel, 2, 1.2 * sch, 1.6 * sch, 0.9, "DMM", "", "");


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

    }
}
